File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2111,14 +2111,16 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
2111
2111
2112
2112
// C-(X+C2) --> (C-C2)-X
2113
2113
if (match (Op1, m_Add (m_Value (X), m_ImmConstant (C2)))) {
2114
- // C-C2 never overflow, and C-(X+C2), (X+C2) has NSW
2115
- // => (C-C2)-X can have NSW
2114
+ // C-C2 never overflow, and C-(X+C2), (X+C2) has NSW/NUW
2115
+ // => (C-C2)-X can have NSW/NUW
2116
2116
bool WillNotSOV = willNotOverflowSignedSub (C, C2, I);
2117
2117
BinaryOperator *Res =
2118
2118
BinaryOperator::CreateSub (ConstantExpr::getSub (C, C2), X);
2119
2119
auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
2120
2120
Res->setHasNoSignedWrap (I.hasNoSignedWrap () && OBO1->hasNoSignedWrap () &&
2121
2121
WillNotSOV);
2122
+ Res->setHasNoUnsignedWrap (I.hasNoUnsignedWrap () &&
2123
+ OBO1->hasNoUnsignedWrap ());
2122
2124
return Res;
2123
2125
}
2124
2126
}
Original file line number Diff line number Diff line change @@ -175,14 +175,24 @@ define i8 @add_nsw_const_const_sub_nsw_ov(i8 %arg) {
175
175
176
176
define i8 @add_nuw_const_const_sub_nuw (i8 %arg ) {
177
177
; CHECK-LABEL: @add_nuw_const_const_sub_nuw(
178
- ; CHECK-NEXT: [[T1:%.*]] = sub i8 -128, [[ARG:%.*]]
178
+ ; CHECK-NEXT: [[T1:%.*]] = sub nuw i8 -128, [[ARG:%.*]]
179
179
; CHECK-NEXT: ret i8 [[T1]]
180
180
;
181
181
%t0 = add nuw i8 %arg , 1
182
182
%t1 = sub nuw i8 -127 , %t0
183
183
ret i8 %t1
184
184
}
185
185
186
+ define i8 @add_nuw_const_const_sub (i8 %arg ) {
187
+ ; CHECK-LABEL: @add_nuw_const_const_sub(
188
+ ; CHECK-NEXT: [[T1:%.*]] = sub i8 -128, [[ARG:%.*]]
189
+ ; CHECK-NEXT: ret i8 [[T1]]
190
+ ;
191
+ %t0 = add nuw i8 %arg , 1
192
+ %t1 = sub i8 -127 , %t0
193
+ ret i8 %t1
194
+ }
195
+
186
196
define i8 @add_const_const_sub_nuw (i8 %arg ) {
187
197
; CHECK-LABEL: @add_const_const_sub_nuw(
188
198
; CHECK-NEXT: [[T1:%.*]] = sub i8 -128, [[ARG:%.*]]
You can’t perform that action at this time.
0 commit comments