From 5e222393cff899512d12d47e49527f838cdc1b48 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Mon, 22 Jul 2019 22:08:45 +0000 Subject: [PATCH] [InstCombine][NFC] Tests for canonicalization of unsigned multiply overflow check git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366748 91177308-0d34-0410-b5e6-96231b3b80d8 --- ...mul-lack-of-overflow-check-via-mul-udiv.ll | 172 ++++++++++++++++++ ...k-of-overflow-check-via-udiv-of-allones.ll | 107 +++++++++++ ...nsigned-mul-overflow-check-via-mul-udiv.ll | 172 ++++++++++++++++++ ...-mul-overflow-check-via-udiv-of-allones.ll | 105 +++++++++++ 4 files changed, 556 insertions(+) create mode 100644 test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-mul-udiv.ll create mode 100644 test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-udiv-of-allones.ll create mode 100644 test/Transforms/InstCombine/unsigned-mul-overflow-check-via-mul-udiv.ll create mode 100644 test/Transforms/InstCombine/unsigned-mul-overflow-check-via-udiv-of-allones.ll diff --git a/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-mul-udiv.ll b/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-mul-udiv.ll new file mode 100644 index 00000000000..11939f48c2b --- /dev/null +++ b/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-mul-udiv.ll @@ -0,0 +1,172 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +; Fold +; ((%x * %y) u/ %x) == %y +; to +; @llvm.umul.with.overflow(%x, %y) + extractvalue + not + +define i1 @t0_basic(i8 %x, i8 %y) { +; CHECK-LABEL: @t0_basic( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) { +; CHECK-LABEL: @t1_vec( +; CHECK-NEXT: [[T0:%.*]] = mul <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv <2 x i8> [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[T1]], [[Y]] +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %t0 = mul <2 x i8> %x, %y + %t1 = udiv <2 x i8> %t0, %x + %r = icmp eq <2 x i8> %t1, %y + ret <2 x i1> %r +} + +declare i8 @gen8() + +define i1 @t2_commutative(i8 %x) { +; CHECK-LABEL: @t2_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define i1 @t3_commutative(i8 %x) { +; CHECK-LABEL: @t3_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define i1 @t4_commutative(i8 %x) { +; CHECK-LABEL: @t4_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Y]], [[T1]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %y, %t1 ; swapped + ret i1 %r +} + +; Extra-use tests + +declare void @use8(i8) + +define i1 @t5_extrause0(i8 %x, i8 %y) { +; CHECK-LABEL: @t5_extrause0( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + call void @use8(i8 %t0) + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define i1 @t6_extrause1(i8 %x, i8 %y) { +; CHECK-LABEL: @t6_extrause1( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: call void @use8(i8 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + call void @use8(i8 %t1) + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define i1 @t7_extrause2(i8 %x, i8 %y) { +; CHECK-LABEL: @t7_extrause2( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: call void @use8(i8 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + call void @use8(i8 %t0) + %t1 = udiv i8 %t0, %x + call void @use8(i8 %t1) + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +; Negative tests + +define i1 @n8_different_x(i8 %x0, i8 %x1, i8 %y) { +; CHECK-LABEL: @n8_different_x( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X0:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X1:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x0, %y + %t1 = udiv i8 %t0, %x1 + %r = icmp eq i8 %t1, %y + ret i1 %r +} + +define i1 @n9_different_y(i8 %x, i8 %y0, i8 %y1) { +; CHECK-LABEL: @n9_different_y( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y0:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[T1]], [[Y1:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y0 + %t1 = udiv i8 %t0, %x + %r = icmp eq i8 %t1, %y1 + ret i1 %r +} + +define i1 @n10_wrong_pred(i8 %x, i8 %y) { +; CHECK-LABEL: @n10_wrong_pred( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + %r = icmp ult i8 %t1, %y + ret i1 %r +} diff --git a/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-udiv-of-allones.ll b/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-udiv-of-allones.ll new file mode 100644 index 00000000000..2865dfafd51 --- /dev/null +++ b/test/Transforms/InstCombine/unsigned-mul-lack-of-overflow-check-via-udiv-of-allones.ll @@ -0,0 +1,107 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +; Fold +; (-1 u/ %x) u>= %y +; to +; @llvm.umul.with.overflow(%x, %y) + extractvalue + not + +define i1 @t0_basic(i8 %x, i8 %y) { +; CHECK-LABEL: @t0_basic( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %r = icmp uge i8 %t0, %y + ret i1 %r +} + +define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) { +; CHECK-LABEL: @t1_vec( +; CHECK-NEXT: [[T0:%.*]] = udiv <2 x i8> , [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp uge <2 x i8> [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %t0 = udiv <2 x i8> , %x + %r = icmp uge <2 x i8> %t0, %y + ret <2 x i1> %r +} + +define <3 x i1> @t2_vec_undef(<3 x i8> %x, <3 x i8> %y) { +; CHECK-LABEL: @t2_vec_undef( +; CHECK-NEXT: [[T0:%.*]] = udiv <3 x i8> , [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp uge <3 x i8> [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret <3 x i1> [[R]] +; + %t0 = udiv <3 x i8> , %x + %r = icmp uge <3 x i8> %t0, %y + ret <3 x i1> %r +} + +declare i8 @gen8() + +define i1 @t3_commutative(i8 %x) { +; CHECK-LABEL: @t3_commutative( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[Y]], [[T0]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %y = call i8 @gen8() + %r = icmp ult i8 %y, %t0 ; swapped + ret i1 %r +} + +; Negative tests + +declare void @use8(i8) + +define i1 @n4_extrause(i8 %x, i8 %y) { +; CHECK-LABEL: @n4_extrause( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + call void @use8(i8 %t0) + %r = icmp uge i8 %t0, %y + ret i1 %r +} + +define i1 @n5_not_negone(i8 %x, i8 %y) { +; CHECK-LABEL: @n5_not_negone( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -2, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -2, %x ; not -1 + %r = icmp uge i8 %t0, %y + ret i1 %r +} + +define i1 @n6_wrong_pred0(i8 %x, i8 %y) { +; CHECK-LABEL: @n6_wrong_pred0( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %r = icmp ule i8 %t0, %y + ret i1 %r +} + +define i1 @n6_wrong_pred1(i8 %x) { +; CHECK-LABEL: @n6_wrong_pred1( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[Y]], [[T0]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %y = call i8 @gen8() + %r = icmp ugt i8 %y, %t0 ; swapped + ret i1 %r +} diff --git a/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-mul-udiv.ll b/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-mul-udiv.ll new file mode 100644 index 00000000000..d6447a77d15 --- /dev/null +++ b/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-mul-udiv.ll @@ -0,0 +1,172 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +; Fold +; ((%x * %y) u/ %x) != %y +; to +; @llvm.umul.with.overflow(%x, %y) + extractvalue + +define i1 @t0_basic(i8 %x, i8 %y) { +; CHECK-LABEL: @t0_basic( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) { +; CHECK-LABEL: @t1_vec( +; CHECK-NEXT: [[T0:%.*]] = mul <2 x i8> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv <2 x i8> [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[T1]], [[Y]] +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %t0 = mul <2 x i8> %x, %y + %t1 = udiv <2 x i8> %t0, %x + %r = icmp ne <2 x i8> %t1, %y + ret <2 x i1> %r +} + +declare i8 @gen8() + +define i1 @t2_commutative(i8 %x) { +; CHECK-LABEL: @t2_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define i1 @t3_commutative(i8 %x) { +; CHECK-LABEL: @t3_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define i1 @t4_commutative(i8 %x) { +; CHECK-LABEL: @t4_commutative( +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[Y]], [[X:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[Y]], [[T1]] +; CHECK-NEXT: ret i1 [[R]] +; + %y = call i8 @gen8() + %t0 = mul i8 %y, %x ; swapped + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %y, %t1 ; swapped + ret i1 %r +} + +; Extra-use tests + +declare void @use8(i8) + +define i1 @t5_extrause0(i8 %x, i8 %y) { +; CHECK-LABEL: @t5_extrause0( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + call void @use8(i8 %t0) + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define i1 @t6_extrause1(i8 %x, i8 %y) { +; CHECK-LABEL: @t6_extrause1( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: call void @use8(i8 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + call void @use8(i8 %t1) + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define i1 @t7_extrause2(i8 %x, i8 %y) { +; CHECK-LABEL: @t7_extrause2( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: call void @use8(i8 [[T1]]) +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + call void @use8(i8 %t0) + %t1 = udiv i8 %t0, %x + call void @use8(i8 %t1) + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +; Negative tests + +define i1 @n8_different_x(i8 %x0, i8 %x1, i8 %y) { +; CHECK-LABEL: @n8_different_x( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X0:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X1:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x0, %y + %t1 = udiv i8 %t0, %x1 + %r = icmp ne i8 %t1, %y + ret i1 %r +} + +define i1 @n9_different_y(i8 %x, i8 %y0, i8 %y1) { +; CHECK-LABEL: @n9_different_y( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y0:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[T1]], [[Y1:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y0 + %t1 = udiv i8 %t0, %x + %r = icmp ne i8 %t1, %y1 + ret i1 %r +} + +define i1 @n10_wrong_pred(i8 %x, i8 %y) { +; CHECK-LABEL: @n10_wrong_pred( +; CHECK-NEXT: [[T0:%.*]] = mul i8 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[T1:%.*]] = udiv i8 [[T0]], [[X]] +; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T1]], [[Y]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = mul i8 %x, %y + %t1 = udiv i8 %t0, %x + %r = icmp ugt i8 %t1, %y + ret i1 %r +} diff --git a/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-udiv-of-allones.ll b/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-udiv-of-allones.ll new file mode 100644 index 00000000000..d66f5f7c40a --- /dev/null +++ b/test/Transforms/InstCombine/unsigned-mul-overflow-check-via-udiv-of-allones.ll @@ -0,0 +1,105 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt %s -instcombine -S | FileCheck %s + +; Fold +; (-1 u/ %x) u< %y +; to +; @llvm.umul.with.overflow(%x, %y) + extractvalue + +define i1 @t0_basic(i8 %x, i8 %y) { +; CHECK-LABEL: @t0_basic( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %r = icmp ult i8 %t0, %y + ret i1 %r +} + +define <2 x i1> @t1_vec(<2 x i8> %x, <2 x i8> %y) { +; CHECK-LABEL: @t1_vec( +; CHECK-NEXT: [[T0:%.*]] = udiv <2 x i8> , [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ult <2 x i8> [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %t0 = udiv <2 x i8> , %x + %r = icmp ult <2 x i8> %t0, %y + ret <2 x i1> %r +} + +define <3 x i1> @t2_vec_undef(<3 x i8> %x, <3 x i8> %y) { +; CHECK-LABEL: @t2_vec_undef( +; CHECK-NEXT: [[T0:%.*]] = udiv <3 x i8> , [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ult <3 x i8> [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret <3 x i1> [[R]] +; + %t0 = udiv <3 x i8> , %x + %r = icmp ult <3 x i8> %t0, %y + ret <3 x i1> %r +} + +declare i8 @gen8() + +define i1 @t3_commutative(i8 %x) { +; CHECK-LABEL: @t3_commutative( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[Y:%.*]] = call i8 @gen8() +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[Y]], [[T0]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %y = call i8 @gen8() + %r = icmp uge i8 %y, %t0 ; swapped + ret i1 %r +} + +; Negative tests + +declare void @use8(i8) + +define i1 @n4_extrause(i8 %x, i8 %y) { +; CHECK-LABEL: @n4_extrause( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: call void @use8(i8 [[T0]]) +; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + call void @use8(i8 %t0) + %r = icmp ult i8 %t0, %y + ret i1 %r +} + +define i1 @n5_not_negone(i8 %x, i8 %y) { +; CHECK-LABEL: @n5_not_negone( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -2, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -2, %x ; not -1 + %r = icmp ult i8 %t0, %y + ret i1 %r +} + +define i1 @n6_wrong_pred0(i8 %x, i8 %y) { +; CHECK-LABEL: @n6_wrong_pred0( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %r = icmp ule i8 %t0, %y + ret i1 %r +} + +define i1 @n6_wrong_pred1(i8 %x, i8 %y) { +; CHECK-LABEL: @n6_wrong_pred1( +; CHECK-NEXT: [[T0:%.*]] = udiv i8 -1, [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[T0]], [[Y:%.*]] +; CHECK-NEXT: ret i1 [[R]] +; + %t0 = udiv i8 -1, %x + %r = icmp ugt i8 %t0, %y + ret i1 %r +} -- 2.40.0