mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
LoopVectorize: Fix a bug in the initialization of reduction variables. AND needs to start at all-one
while XOR, and OR need to start at zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167032 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c197a55019
commit
cc03331caa
@ -211,8 +211,6 @@ public:
|
|||||||
TheLoop(Lp), SE(Se), DL(Dl), Induction(0) { }
|
TheLoop(Lp), SE(Se), DL(Dl), Induction(0) { }
|
||||||
|
|
||||||
/// This represents the kinds of reductions that we support.
|
/// This represents the kinds of reductions that we support.
|
||||||
/// We use the enum values to hold the 'identity' value for
|
|
||||||
/// each operand. This value does not change the result if applied.
|
|
||||||
enum ReductionKind {
|
enum ReductionKind {
|
||||||
NoReduction = -1, /// Not a reduction.
|
NoReduction = -1, /// Not a reduction.
|
||||||
IntegerAdd = 0, /// Sum of numbers.
|
IntegerAdd = 0, /// Sum of numbers.
|
||||||
@ -523,7 +521,7 @@ SingleBlockLoopVectorizer::getUniformVector(unsigned Val, Type* ScalarTy) {
|
|||||||
SmallVector<Constant*, 8> Indices;
|
SmallVector<Constant*, 8> Indices;
|
||||||
// Create a vector of consecutive numbers from zero to VF.
|
// Create a vector of consecutive numbers from zero to VF.
|
||||||
for (unsigned i = 0; i < VF; ++i)
|
for (unsigned i = 0; i < VF; ++i)
|
||||||
Indices.push_back(ConstantInt::get(ScalarTy, Val));
|
Indices.push_back(ConstantInt::get(ScalarTy, Val, true));
|
||||||
|
|
||||||
// Add the consecutive indices to the vector value.
|
// Add the consecutive indices to the vector value.
|
||||||
return ConstantVector::get(Indices);
|
return ConstantVector::get(Indices);
|
||||||
@ -750,6 +748,23 @@ SingleBlockLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) {
|
|||||||
LoopBypassBlock = BypassBlock;
|
LoopBypassBlock = BypassBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned
|
||||||
|
getReductionIdentity(LoopVectorizationLegality::ReductionKind K) {
|
||||||
|
switch (K) {
|
||||||
|
case LoopVectorizationLegality::IntegerXor:
|
||||||
|
case LoopVectorizationLegality::IntegerAdd:
|
||||||
|
case LoopVectorizationLegality::IntegerOr:
|
||||||
|
return 0;
|
||||||
|
case LoopVectorizationLegality::IntegerMult:
|
||||||
|
return 1;
|
||||||
|
case LoopVectorizationLegality::IntegerAnd:
|
||||||
|
return -1;
|
||||||
|
default:
|
||||||
|
llvm_unreachable("Unknown reduction kind");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SingleBlockLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) {
|
SingleBlockLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) {
|
||||||
//===------------------------------------------------===//
|
//===------------------------------------------------===//
|
||||||
@ -974,10 +989,9 @@ SingleBlockLoopVectorizer::vectorizeLoop(LoopVectorizationLegality *Legal) {
|
|||||||
Value *VectorExit = getVectorValue(RdxDesc.LoopExitInstr);
|
Value *VectorExit = getVectorValue(RdxDesc.LoopExitInstr);
|
||||||
Type *VecTy = VectorExit->getType();
|
Type *VecTy = VectorExit->getType();
|
||||||
|
|
||||||
// Find the reduction identity variable. The value of the enum is the
|
// Find the reduction identity variable. Zero for addition, or, xor,
|
||||||
// identity. Zero for addition. One for Multiplication.
|
// one for multiplication, -1 for And.
|
||||||
unsigned IdentitySclr = RdxDesc.Kind;
|
Constant *Identity = getUniformVector(getReductionIdentity(RdxDesc.Kind),
|
||||||
Constant *Identity = getUniformVector(IdentitySclr,
|
|
||||||
VecTy->getScalarType());
|
VecTy->getScalarType());
|
||||||
|
|
||||||
// This vector is the Identity vector where the first element is the
|
// This vector is the Identity vector where the first element is the
|
||||||
|
@ -151,6 +151,7 @@ for.end: ; preds = %for.body, %entry
|
|||||||
|
|
||||||
;CHECK: @reduction_and
|
;CHECK: @reduction_and
|
||||||
;CHECK: and <4 x i32>
|
;CHECK: and <4 x i32>
|
||||||
|
;CHECK: <i32 -1, i32 -1, i32 -1, i32 -1>
|
||||||
;CHECK: ret i32
|
;CHECK: ret i32
|
||||||
define i32 @reduction_and(i32 %n, i32* nocapture %A, i32* nocapture %B) nounwind uwtable readonly {
|
define i32 @reduction_and(i32 %n, i32* nocapture %A, i32* nocapture %B) nounwind uwtable readonly {
|
||||||
entry:
|
entry:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user