diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-01-27 06:21:43 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-01-27 06:21:43 +0000 |
commit | 4c82daea60cc6f51a0797ae21c0bcc6d38e56853 (patch) | |
tree | 90c49cb84fdc930ba76e41aa9bb4291103f396f5 | |
parent | b9f60c17dcdbc3601ab2575eb17b91be1c8aa071 (diff) | |
download | bcm5719-llvm-4c82daea60cc6f51a0797ae21c0bcc6d38e56853.tar.gz bcm5719-llvm-4c82daea60cc6f51a0797ae21c0bcc6d38e56853.zip |
LoopRotate: Don't walk the uses of a Constant
LoopRotate wanted to avoid live range interference by looking at the
uses of a Value in the loop latch and seeing if any lied outside of the
loop. We would wrongly perform this operation on Constants.
This fixes PR22337.
llvm-svn: 227171
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopRotation.cpp | 19 | ||||
-rw-r--r-- | llvm/test/Transforms/LoopRotate/pr22337.ll | 24 |
2 files changed, 32 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp index c37cd917ad2..02fb80c0cd5 100644 --- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp +++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp @@ -229,20 +229,17 @@ static bool shouldSpeculateInstrs(BasicBlock::iterator Begin, case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: { - Value *IVOpnd = nullptr; - if (isa<ConstantInt>(I->getOperand(0))) - IVOpnd = I->getOperand(1); - - if (isa<ConstantInt>(I->getOperand(1))) { - if (IVOpnd) - return false; - - IVOpnd = I->getOperand(0); - } + Value *IVOpnd = !isa<Constant>(I->getOperand(0)) + ? I->getOperand(0) + : !isa<Constant>(I->getOperand(1)) + ? I->getOperand(1) + : nullptr; + if (!IVOpnd) + return false; // If increment operand is used outside of the loop, this speculation // could cause extra live range interference. - if (MultiExitLoop && IVOpnd) { + if (MultiExitLoop) { for (User *UseI : IVOpnd->users()) { auto *UserInst = cast<Instruction>(UseI); if (!L->contains(UserInst)) diff --git a/llvm/test/Transforms/LoopRotate/pr22337.ll b/llvm/test/Transforms/LoopRotate/pr22337.ll new file mode 100644 index 00000000000..c2893db2c47 --- /dev/null +++ b/llvm/test/Transforms/LoopRotate/pr22337.ll @@ -0,0 +1,24 @@ +; RUN: opt < %s -loop-rotate -S | FileCheck %s + +@a = external global i8, align 4 +@tmp = global i8* @a + +define void @f() { +; CHECK-LABEL: define void @f( +; CHECK: getelementptr i8* @a, i32 0 +entry: + br label %for.preheader + +for.preheader: + br i1 undef, label %if.then8, label %for.body + +for.body: + br i1 undef, label %if.end, label %if.then8 + +if.end: + %arrayidx = getelementptr i8* @a, i32 0 + br label %for.preheader + +if.then8: + unreachable +} |