From a4b8059ee2e42747fce054bafd502d932e7defa5 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Wed, 7 Apr 2021 11:50:06 +0300 Subject: [PATCH] [NFC][InstCombine] Add sub-of-sub tests with constant expressions These would cause endless combine loop after 31d219d2997fed1b7dc97e0adf170d5aaf65883e. --- test/Transforms/InstCombine/sub-from-sub.ll | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/Transforms/InstCombine/sub-from-sub.ll b/test/Transforms/InstCombine/sub-from-sub.ll index 202dbd1072a..0d5885a740f 100644 --- a/test/Transforms/InstCombine/sub-from-sub.ll +++ b/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 +@g0 = external global i8, align 1 +@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 +}