diff options
| author | Evan Cheng <evan.cheng@apple.com> | 2012-07-12 01:45:35 +0000 |
|---|---|---|
| committer | Evan Cheng <evan.cheng@apple.com> | 2012-07-12 01:45:35 +0000 |
| commit | 493eb32ff45cebb7ea227a33955a565933879ed0 (patch) | |
| tree | 59bdcccdc511543f77ad5df75e8628920da2d522 /llvm/lib/Transforms | |
| parent | 17ce5b977b6330005205390e3025159ed0143f1e (diff) | |
| download | bcm5719-llvm-493eb32ff45cebb7ea227a33955a565933879ed0.tar.gz bcm5719-llvm-493eb32ff45cebb7ea227a33955a565933879ed0.zip | |
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
llvm-svn: 160101
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 125c74a89a1..0a622424368 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/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; } |

