diff options
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 7 |
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; } |