From 133feded89e2b2d1bd8d7c2e0a39f248764942a6 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 1 Oct 2019 17:49:58 +0000 Subject: [PATCH] [NFC][InstCombine] (Better) tests for sign-bit-smearing pattern https://rise4fun.com/Alive/JRU https://rise4fun.com/Alive/yR4 <- we can preserve 'exact' git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373362 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../high-bit-signmask-with-trunc.ll | 153 ++++++++++++++++++ .../InstCombine/high-bit-signmask.ll | 126 +++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll create mode 100644 test/Transforms/InstCombine/high-bit-signmask.ll diff --git a/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll b/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll new file mode 100644 index 00000000000..5abd5963ed2 --- /dev/null +++ b/test/Transforms/InstCombine/high-bit-signmask-with-trunc.ll @@ -0,0 +1,153 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +define i32 @t0(i64 %x) { +; CHECK-LABEL: @t0( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} +define i32 @t1_exact(i64 %x) { +; CHECK-LABEL: @t1_exact( +; CHECK-NEXT: [[T0:%.*]] = lshr exact i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr exact i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} +define i32 @t2(i64 %x) { +; CHECK-LABEL: @t2( +; CHECK-NEXT: [[T0:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = ashr i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} +define i32 @t3_exact(i64 %x) { +; CHECK-LABEL: @t3_exact( +; CHECK-NEXT: [[T0:%.*]] = ashr exact i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = ashr exact i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} + +define <2 x i32> @t4(<2 x i64> %x) { +; CHECK-LABEL: @t4( +; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i64> [[X:%.*]], +; CHECK-NEXT: [[T1:%.*]] = trunc <2 x i64> [[T0]] to <2 x i32> +; CHECK-NEXT: [[R:%.*]] = sub nsw <2 x i32> zeroinitializer, [[T1]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %t0 = lshr <2 x i64> %x, + %t1 = trunc <2 x i64> %t0 to <2 x i32> + %r = sub <2 x i32> zeroinitializer, %t1 + ret <2 x i32> %r +} + +define <2 x i32> @t5(<2 x i64> %x) { +; CHECK-LABEL: @t5( +; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i64> [[X:%.*]], +; CHECK-NEXT: [[T1:%.*]] = trunc <2 x i64> [[T0]] to <2 x i32> +; CHECK-NEXT: [[R:%.*]] = sub <2 x i32> , [[T1]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %t0 = lshr <2 x i64> %x, + %t1 = trunc <2 x i64> %t0 to <2 x i32> + %r = sub <2 x i32> , %t1 + ret <2 x i32> %r +} + +declare void @use64(i64) +declare void @use32(i32) + +define i32 @t6(i64 %x) { +; CHECK-LABEL: @t6( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: call void @use64(i64 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 63 + call void @use64(i64 %t0) + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} + +define i32 @n7(i64 %x) { +; CHECK-LABEL: @n7( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: call void @use32(i32 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + call void @use32(i32 %t1) + %r = sub i32 0, %t1 + ret i32 %r +} + +define i32 @n8(i64 %x) { +; CHECK-LABEL: @n8( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: call void @use64(i64 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: call void @use32(i32 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 63 + call void @use64(i64 %t0) + %t1 = trunc i64 %t0 to i32 + call void @use32(i32 %t1) + %r = sub i32 0, %t1 + ret i32 %r +} + +define i32 @n9(i64 %x) { +; CHECK-LABEL: @n9( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 62 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[T1]] +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 62 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 0, %t1 + ret i32 %r +} + +define i32 @n10(i64 %x) { +; CHECK-LABEL: @n10( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[T1:%.*]] = trunc i64 [[T0]] to i32 +; CHECK-NEXT: [[R:%.*]] = xor i32 [[T1]], 1 +; CHECK-NEXT: ret i32 [[R]] +; + %t0 = lshr i64 %x, 63 + %t1 = trunc i64 %t0 to i32 + %r = sub i32 1, %t1 + ret i32 %r +} diff --git a/test/Transforms/InstCombine/high-bit-signmask.ll b/test/Transforms/InstCombine/high-bit-signmask.ll new file mode 100644 index 00000000000..7c771f43dd4 --- /dev/null +++ b/test/Transforms/InstCombine/high-bit-signmask.ll @@ -0,0 +1,126 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +define i64 @t0(i64 %x) { +; CHECK-LABEL: @t0( +; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 63 + %r = sub i64 0, %t0 + ret i64 %r +} +define i64 @t0_exact(i64 %x) { +; CHECK-LABEL: @t0_exact( +; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X:%.*]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr exact i64 %x, 63 + %r = sub i64 0, %t0 + ret i64 %r +} +define i64 @t2(i64 %x) { +; CHECK-LABEL: @t2( +; CHECK-NEXT: [[R:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = ashr i64 %x, 63 + %r = sub i64 0, %t0 + ret i64 %r +} +define i64 @t3_exact(i64 %x) { +; CHECK-LABEL: @t3_exact( +; CHECK-NEXT: [[R:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = ashr exact i64 %x, 63 + %r = sub i64 0, %t0 + ret i64 %r +} + +define <2 x i64> @t4(<2 x i64> %x) { +; CHECK-LABEL: @t4( +; CHECK-NEXT: [[R:%.*]] = ashr <2 x i64> [[X:%.*]], +; CHECK-NEXT: ret <2 x i64> [[R]] +; + %t0 = lshr <2 x i64> %x, + %r = sub <2 x i64> zeroinitializer, %t0 + ret <2 x i64> %r +} + +define <2 x i64> @t5(<2 x i64> %x) { +; CHECK-LABEL: @t5( +; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i64> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = sub <2 x i64> , [[T0]] +; CHECK-NEXT: ret <2 x i64> [[R]] +; + %t0 = lshr <2 x i64> %x, + %r = sub <2 x i64> , %t0 + ret <2 x i64> %r +} + +declare void @use64(i64) +declare void @use32(i64) + +define i64 @t6(i64 %x) { +; CHECK-LABEL: @t6( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: call void @use64(i64 [[T0]]) +; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 63 + call void @use64(i64 %t0) + %r = sub i64 0, %t0 + ret i64 %r +} + +define i64 @n7(i64 %x) { +; CHECK-LABEL: @n7( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: call void @use32(i64 [[T0]]) +; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 63 + call void @use32(i64 %t0) + %r = sub i64 0, %t0 + ret i64 %r +} + +define i64 @n8(i64 %x) { +; CHECK-LABEL: @n8( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: call void @use64(i64 [[T0]]) +; CHECK-NEXT: call void @use32(i64 [[T0]]) +; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X]], 63 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 63 + call void @use64(i64 %t0) + call void @use32(i64 %t0) + %r = sub i64 0, %t0 + ret i64 %r +} + +define i64 @n9(i64 %x) { +; CHECK-LABEL: @n9( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 62 +; CHECK-NEXT: [[R:%.*]] = sub nsw i64 0, [[T0]] +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 62 + %r = sub i64 0, %t0 + ret i64 %r +} + +define i64 @n10(i64 %x) { +; CHECK-LABEL: @n10( +; CHECK-NEXT: [[T0:%.*]] = lshr i64 [[X:%.*]], 63 +; CHECK-NEXT: [[R:%.*]] = xor i64 [[T0]], 1 +; CHECK-NEXT: ret i64 [[R]] +; + %t0 = lshr i64 %x, 63 + %r = sub i64 1, %t0 + ret i64 %r +} -- 2.40.0