From 1708788d2d1091d1663cd859c5913121463a6b73 Mon Sep 17 00:00:00 2001 From: Noah Goldstein Date: Mon, 22 Apr 2024 16:01:03 -0500 Subject: [InstCombine] Add non-splat test for `(icmp (lshr x, y), x)`; NFC --- .../Transforms/InstCombine/icmp-div-constant.ll | 63 +++++++++++++++++++--- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/icmp-div-constant.ll b/llvm/test/Transforms/InstCombine/icmp-div-constant.ll index b047715..d815e09 100644 --- a/llvm/test/Transforms/InstCombine/icmp-div-constant.ll +++ b/llvm/test/Transforms/InstCombine/icmp-div-constant.ll @@ -118,8 +118,8 @@ define i32 @icmp_div(i16 %a, i16 %c) { ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]] ; CHECK: then: -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0 -; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP]] to i32 +; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i16 [[C:%.*]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP_NOT]] to i32 ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[TMP0]], [[THEN]] ] @@ -173,8 +173,8 @@ define i32 @icmp_div3(i16 %a, i16 %c) { ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]] ; CHECK: then: -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0 -; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP]] to i32 +; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i16 [[C:%.*]], 0 +; CHECK-NEXT: [[TMP0:%.*]] = sext i1 [[CMP_NOT]] to i32 ; CHECK-NEXT: br label [[EXIT]] ; CHECK: exit: ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[TMP0]], [[THEN]] ] @@ -381,8 +381,8 @@ define i1 @sdiv_eq_smin_use(i32 %x, i32 %y) { define i1 @sdiv_x_by_const_cmp_x(i32 %x) { ; CHECK-LABEL: @sdiv_x_by_const_cmp_x( -; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[X:%.*]], 0 -; CHECK-NEXT: ret i1 [[TMP1]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X:%.*]], 0 +; CHECK-NEXT: ret i1 [[R]] ; %v = sdiv i32 %x, 13 %r = icmp eq i32 %v, %x @@ -399,12 +399,35 @@ define i1 @udiv_x_by_const_cmp_x(i32 %x) { ret i1 %2 } +define <2 x i1> @udiv_x_by_const_cmp_x_non_splat(<2 x i32> %x) { +; CHECK-LABEL: @udiv_x_by_const_cmp_x_non_splat( +; CHECK-NEXT: [[TMP1:%.*]] = udiv <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[TMP2:%.*]] = icmp slt <2 x i32> [[TMP1]], [[X]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = udiv <2 x i32> %x, + %2 = icmp slt <2 x i32> %1, %x + ret <2 x i1> %2 +} + + +define <2 x i1> @sdiv_x_by_const_cmp_x_non_splat(<2 x i32> %x) { +; CHECK-LABEL: @sdiv_x_by_const_cmp_x_non_splat( +; CHECK-NEXT: [[TMP1:%.*]] = sdiv <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i32> [[TMP1]], [[X]] +; CHECK-NEXT: ret <2 x i1> [[TMP2]] +; + %1 = sdiv <2 x i32> %x, + %2 = icmp eq <2 x i32> %1, %x + ret <2 x i1> %2 +} + ; Same as above but with right shift instead of division (C != 0) define i1 @lshr_x_by_const_cmp_x(i32 %x) { ; CHECK-LABEL: @lshr_x_by_const_cmp_x( -; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[X:%.*]], 0 -; CHECK-NEXT: ret i1 [[TMP1]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[X:%.*]], 0 +; CHECK-NEXT: ret i1 [[R]] ; %v = lshr i32 %x, 1 %r = icmp eq i32 %v, %x @@ -421,6 +444,30 @@ define <4 x i1> @lshr_by_const_cmp_sle_value(<4 x i32> %x) { ret <4 x i1> %r } +define <4 x i1> @lshr_by_const_cmp_sle_value_non_splat(<4 x i32> %x) { +; CHECK-LABEL: @lshr_by_const_cmp_sle_value_non_splat( +; CHECK-NEXT: [[V:%.*]] = lshr <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = icmp sle <4 x i32> [[V]], [[X]] +; CHECK-NEXT: ret <4 x i1> [[R]] +; + %v = lshr <4 x i32> %x, + %r = icmp sle <4 x i32> %v, %x + ret <4 x i1> %r +} + + +define <4 x i1> @ashr_by_const_cmp_sge_value_non_splat(<4 x i32> %x) { +; CHECK-LABEL: @ashr_by_const_cmp_sge_value_non_splat( +; CHECK-NEXT: [[V:%.*]] = ashr <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = icmp sge <4 x i32> [[V]], [[X]] +; CHECK-NEXT: ret <4 x i1> [[R]] +; + %v = ashr <4 x i32> %x, + %r = icmp sge <4 x i32> %v, %x + ret <4 x i1> %r +} + + define i1 @lshr_by_const_cmp_sge_value(i32 %x) { ; CHECK-LABEL: @lshr_by_const_cmp_sge_value( ; CHECK-NEXT: [[R:%.*]] = icmp slt i32 [[X:%.*]], 1 -- cgit v1.1