[llvm] c972e2d - [NFC][InstCombine] Add sub-of-sub tests with constant expressions

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 7 02:08:11 PDT 2021


Author: Roman Lebedev
Date: 2021-04-07T12:06:24+03:00
New Revision: c972e2d1c29fc248e47f1c502f90472a1c26b256

URL: https://github.com/llvm/llvm-project/commit/c972e2d1c29fc248e47f1c502f90472a1c26b256
DIFF: https://github.com/llvm/llvm-project/commit/c972e2d1c29fc248e47f1c502f90472a1c26b256.diff

LOG: [NFC][InstCombine] Add sub-of-sub tests with constant expressions

These would cause endless combine loop after 31d219d2997fed1b7dc97e0adf170d5aaf65883e.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/sub-from-sub.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub-from-sub.ll b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
index 202dbd1072a4..0d5885a740f0 100644
--- a/llvm/test/Transforms/InstCombine/sub-from-sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub-from-sub.ll
@@ -168,3 +168,34 @@ define i8 @t12_c1_c2_exrause(i8 %x, i8 %z) {
   %r = sub i8 %i0, 24
   ret i8 %r
 }
+
+; PR49870
+ at g0 = external global i8, align 1
+ at g1 = external global i8, align 1
+define i32 @constantexpr0(i32 %x, i8* %y) unnamed_addr {
+; CHECK-LABEL: @constantexpr0(
+; CHECK-NEXT:    [[R:%.*]] = sub i32 sub (i32 0, i32 ptrtoint (i8* @g0 to i32)), [[X:%.*]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %i0 = add i32 %x, ptrtoint (i8* @g0 to i32)
+  %r = sub i32 0, %i0
+  ret i32 %r
+}
+define i32 @constantexpr1(i32 %x, i8* %y) unnamed_addr {
+; CHECK-LABEL: @constantexpr1(
+; CHECK-NEXT:    [[R:%.*]] = sub i32 sub (i32 ptrtoint (i8* @g1 to i32), i32 42), [[X:%.*]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %i0 = add i32 %x, 42
+  %r = sub i32 ptrtoint (i8* @g1 to i32), %i0
+  ret i32 %r
+}
+define i32 @constantexpr2(i32 %x, i8* %y) unnamed_addr {
+; CHECK-LABEL: @constantexpr2(
+; CHECK-NEXT:    [[R:%.*]] = sub i32 sub (i32 ptrtoint (i8* @g1 to i32), i32 ptrtoint (i8* @g0 to i32)), [[X:%.*]]
+; CHECK-NEXT:    ret i32 [[R]]
+;
+  %i0 = add i32 %x, ptrtoint (i8* @g0 to i32)
+  %r = sub i32 ptrtoint (i8* @g1 to i32), %i0
+  ret i32 %r
+}


        


More information about the llvm-commits mailing list