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 +}