File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -1548,8 +1548,12 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
1548
1548
}
1549
1549
1550
1550
// A + -B --> A - B
1551
- if (match (RHS, m_Neg (m_Value (B))))
1552
- return BinaryOperator::CreateSub (LHS, B);
1551
+ if (match (RHS, m_Neg (m_Value (B)))) {
1552
+ auto *Sub = BinaryOperator::CreateSub (LHS, B);
1553
+ auto *OBO = cast<OverflowingBinaryOperator>(RHS);
1554
+ Sub->setHasNoSignedWrap (I.hasNoSignedWrap () && OBO->hasNoSignedWrap ());
1555
+ return Sub;
1556
+ }
1553
1557
1554
1558
if (Value *V = checkForNegativeOperand (I, Builder))
1555
1559
return replaceInstUsesWith (I, V);
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ define i32 @test4(i32 %A, i32 %BB) {
114
114
define i32 @test4_both_nsw (i32 %A , i32 %BB ) {
115
115
; CHECK-LABEL: @test4_both_nsw(
116
116
; CHECK-NEXT: [[B:%.*]] = xor i32 [[BB:%.*]], 1
117
- ; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[A:%.*]]
117
+ ; CHECK-NEXT: [[D:%.*]] = sub nsw i32 [[B]], [[A:%.*]]
118
118
; CHECK-NEXT: ret i32 [[D]]
119
119
;
120
120
%B = xor i32 %BB , 1 ; thwart complexity-based canonicalization
You can’t perform that action at this time.
0 commit comments