mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 00:24:26 +00:00
[Reassociate] Better preserve NSW/NUW flags.
Part of PR12985. Phabricator Revision: http://reviews.llvm.org/D6172 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221555 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1031,8 +1031,19 @@ static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
|
||||
BinaryOperator::CreateMul(Shl->getOperand(0), MulCst, "", Shl);
|
||||
Shl->setOperand(0, UndefValue::get(Shl->getType())); // Drop use of op.
|
||||
Mul->takeName(Shl);
|
||||
|
||||
// Everyone now refers to the mul instruction.
|
||||
Shl->replaceAllUsesWith(Mul);
|
||||
Mul->setDebugLoc(Shl->getDebugLoc());
|
||||
|
||||
// We can safely preserve the nuw flag in all cases. It's also safe to turn a
|
||||
// nuw nsw shl into a nuw nsw mul. However, nsw in isolation requires special
|
||||
// handling.
|
||||
bool NSW = cast<BinaryOperator>(Shl)->hasNoSignedWrap();
|
||||
bool NUW = cast<BinaryOperator>(Shl)->hasNoUnsignedWrap();
|
||||
if (NSW && NUW)
|
||||
Mul->setHasNoSignedWrap(true);
|
||||
Mul->setHasNoUnsignedWrap(NUW);
|
||||
return Mul;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user