aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2012-07-12 01:45:35 +0000
committerEvan Cheng <evan.cheng@apple.com>2012-07-12 01:45:35 +0000
commit79590b8edffd403d93c764887a4f0ad4f2612914 (patch)
tree369b97c645dc9744eb827927a9ecd66ed3b10a66 /lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
parente96ce46b4deabec1110fd9d58213cb884a33b61c (diff)
Instcombine was transforming:
%shr = lshr i64 %key, 3 %0 = load i64* %val, align 8 %sub = add i64 %0, -1 %and = and i64 %sub, %shr ret i64 %and to: %shr = lshr i64 %key, 3 %0 = load i64* %val, align 8 %sub = add i64 %0, 2305843009213693951 %and = and i64 %sub, %shr ret i64 %and The demanded bit optimization is actually a pessimization because add -1 would be codegen'ed as a sub 1. Teach the demanded constant shrinking optimization to check for negated constant to make sure it is actually reducing the width of the constant. rdar://11793464 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 125c74a89a..0a62242436 100644
--- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -40,6 +40,13 @@ static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo,
// This instruction is producing bits that are not demanded. Shrink the RHS.
Demanded &= OpC->getValue();
+ if (I->getOpcode() == Instruction::Add) {
+ // However, if the instruction is an add then the constant may be negated
+ // when the opcode is changed to sub. Check if the transformation is really
+ // shrinking the constant.
+ if (Demanded.abs().getActiveBits() > OpC->getValue().abs().getActiveBits())
+ return false;
+ }
I->setOperand(OpNo, ConstantInt::get(OpC->getType(), Demanded));
return true;
}