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

