[PATCH] D152091: [InstCombine] precommit test for D152068(NFC)

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 3 21:35:13 PDT 2023


khei4 created this revision.
khei4 added reviewers: nikic, goldstein.w.n, spatel.
Herald added a subscriber: StephenFan.
Herald added a project: All.
khei4 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

precommit test for D152068 <https://reviews.llvm.org/D152068>


https://reviews.llvm.org/D152091

Files:
  llvm/test/Transforms/InstCombine/addsub-constant-folding.ll


Index: llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
===================================================================
--- llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
+++ llvm/test/Transforms/InstCombine/addsub-constant-folding.ll
@@ -132,6 +132,47 @@
   ret i32 %t1
 }
 
+define i32 @add_nsw_const_const_sub_nsw(i32 %arg) {
+; CHECK-LABEL: @add_nsw_const_const_sub_nsw(
+; CHECK-NEXT:    [[T1:%.*]] = sub i32 -2147483648, [[ARG:%.*]]
+; CHECK-NEXT:    ret i32 [[T1]]
+;
+  %t0 = add nsw i32 %arg, 1
+  %t1 = sub nsw i32 -2147483647, %t0
+  ret i32 %t1
+}
+
+define i32 @add_nsw_const_const_sub(i32 %arg) {
+; CHECK-LABEL: @add_nsw_const_const_sub(
+; CHECK-NEXT:    [[T1:%.*]] = sub i32 -2147483648, [[ARG:%.*]]
+; CHECK-NEXT:    ret i32 [[T1]]
+;
+  %t0 = add nsw i32 %arg, 1
+  %t1 = sub i32 -2147483647, %t0
+  ret i32 %t1
+}
+
+define i32 @add_const_const_sub_nsw(i32 %arg) {
+; CHECK-LABEL: @add_const_const_sub_nsw(
+; CHECK-NEXT:    [[T1:%.*]] = sub i32 -2147483648, [[ARG:%.*]]
+; CHECK-NEXT:    ret i32 [[T1]]
+;
+  %t0 = add i32 %arg, 1
+  %t1 = sub nsw i32 -2147483647, %t0
+  ret i32 %t1
+}
+
+; 2147483647-X with nsw will be more poisonous than -2147483647-(X+2) with nsw. (see X = -1)
+define i32 @add_nsw_const_const_sub_nsw_ov(i32 %arg) {
+; CHECK-LABEL: @add_nsw_const_const_sub_nsw_ov(
+; CHECK-NEXT:    [[T1:%.*]] = sub i32 2147483647, [[ARG:%.*]]
+; CHECK-NEXT:    ret i32 [[T1]]
+;
+  %t0 = add nsw i32 %arg, 2
+  %t1 = sub nsw i32 -2147483647, %t0
+  ret i32 %t1
+}
+
 define i32 @add_const_const_sub_extrause(i32 %arg) {
 ; CHECK-LABEL: @add_const_const_sub_extrause(
 ; CHECK-NEXT:    [[T0:%.*]] = add i32 [[ARG:%.*]], 8


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152091.528182.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230604/44c4bd2f/attachment.bin>


More information about the llvm-commits mailing list