[llvm] [InstCombine] When -A + B both have nsw flag, set nsw flag. (PR #72127)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 21:46:09 PST 2023
================
@@ -1487,7 +1487,11 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
return BinaryOperator::CreateNeg(Builder.CreateAdd(A, B));
// -A + B --> B - A
- return BinaryOperator::CreateSub(RHS, A);
+ auto *Sub = BinaryOperator::CreateSub(RHS, A);
+ auto *OB0 = dyn_cast<OverflowingBinaryOperator>(LHS);
+ Sub->setHasNoSignedWrap(I.hasNoSignedWrap() && OB0->hasNoSignedWrap());
----------------
goldsteinn wrote:
yeah, sorry I misread.
https://github.com/llvm/llvm-project/pull/72127
More information about the llvm-commits
mailing list