From e1cebe9ed12a46282fb6cc9fa9e172b04e5474ef Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 29 Jan 2023 11:53:38 -0500 Subject: [PATCH] [InstCombine] add tests for icmp-of-and-of-select-of-constants; NFC This overlaps with the tests proposed in D134064 and providing coverage for D133919, but it is both limited in scope and more comprehensive because there are many potential ways to transform these kinds of patterns. --- llvm/test/Transforms/InstCombine/icmp-select.ll | 151 +++++++++++++++++++++++- 1 file changed, 149 insertions(+), 2 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/icmp-select.ll b/llvm/test/Transforms/InstCombine/icmp-select.ll index 8217872..0c7b145 100644 --- a/llvm/test/Transforms/InstCombine/icmp-select.ll +++ b/llvm/test/Transforms/InstCombine/icmp-select.ll @@ -192,8 +192,8 @@ define i1 @icmp_select_implied_cond_ne(i8 %x, i8 %y) { define i1 @icmp_select_implied_cond_swapped_select(i8 %x, i8 %y) { ; CHECK-LABEL: @icmp_select_implied_cond_swapped_select( ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[X:%.*]], 0 -; CHECK-NEXT: [[CMP21:%.*]] = icmp eq i8 [[Y:%.*]], 0 -; CHECK-NEXT: [[CMP2:%.*]] = select i1 [[CMP1]], i1 [[CMP21]], i1 false +; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[Y:%.*]], 0 +; CHECK-NEXT: [[CMP2:%.*]] = select i1 [[CMP1]], i1 [[TMP1]], i1 false ; CHECK-NEXT: ret i1 [[CMP2]] ; %cmp1 = icmp eq i8 %x, 0 @@ -259,3 +259,150 @@ define i1 @umin_seq_comparison(i8 %x, i8 %y) { %cmp2 = icmp eq i8 %sel, %x ret i1 %cmp2 } + +define i1 @select_constants_and_icmp_eq0(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 2, i8 1 +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 2, i8 1 +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 2, i8 1 + %s2 = select i1 %y, i8 2, i8 1 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq0_uses(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_uses( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 2, i8 1 +; CHECK-NEXT: call void @use(i8 [[S1]]) +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 2, i8 1 +; CHECK-NEXT: call void @use(i8 [[S2]]) +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: call void @use(i8 [[AND]]) +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 2, i8 1 + call void @use(i8 %s1) + %s2 = select i1 %y, i8 2, i8 1 + call void @use(i8 %s2) + %and = and i8 %s1, %s2 + call void @use(i8 %and) + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define <2 x i1> @select_constants_and_icmp_eq0_vec_splat(<2 x i1> %x, <2 x i1> %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_vec_splat( +; CHECK-NEXT: [[S1:%.*]] = select <2 x i1> [[X:%.*]], <2 x i9> , <2 x i9> +; CHECK-NEXT: [[S2:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i9> , <2 x i9> +; CHECK-NEXT: [[AND:%.*]] = and <2 x i9> [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i9> [[AND]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %s1 = select <2 x i1> %x, <2 x i9> , <2 x i9> + %s2 = select <2 x i1> %y, <2 x i9> , <2 x i9> + %and = and <2 x i9> %s1, %s2 + %cmp = icmp eq <2 x i9> %and, zeroinitializer + ret <2 x i1> %cmp +} + +define i1 @select_constants_and_icmp_eq0_common_bit(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_common_bit( +; CHECK-NEXT: ret i1 false +; + %s1 = select i1 %x, i8 2, i8 3 + %s2 = select i1 %y, i8 2, i8 3 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq0_no_common_op1(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_no_common_op1( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 16, i8 3 +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 24, i8 3 +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 16, i8 3 + %s2 = select i1 %y, i8 24, i8 3 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq0_no_common_op2(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_no_common_op2( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 16, i8 3 +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 16, i8 7 +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 16, i8 3 + %s2 = select i1 %y, i8 16, i8 7 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq0_zero_tval(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_zero_tval( +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]] +; CHECK-NEXT: ret i1 [[TMP1]] +; + %s1 = select i1 %x, i8 0, i8 12 + %s2 = select i1 %y, i8 0, i8 12 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq0_zero_fval(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq0_zero_fval( +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false +; CHECK-NEXT: [[NOT_:%.*]] = xor i1 [[TMP1]], true +; CHECK-NEXT: ret i1 [[NOT_]] +; + %s1 = select i1 %x, i8 12, i8 0 + %s2 = select i1 %y, i8 12, i8 0 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 0 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq_tval(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq_tval( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 6, i8 1 +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 6, i8 1 +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 6 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 6, i8 1 + %s2 = select i1 %y, i8 6, i8 1 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 6 + ret i1 %cmp +} + +define i1 @select_constants_and_icmp_eq_fval(i1 %x, i1 %y) { +; CHECK-LABEL: @select_constants_and_icmp_eq_fval( +; CHECK-NEXT: [[S1:%.*]] = select i1 [[X:%.*]], i8 12, i8 3 +; CHECK-NEXT: [[S2:%.*]] = select i1 [[Y:%.*]], i8 12, i8 3 +; CHECK-NEXT: [[AND:%.*]] = and i8 [[S1]], [[S2]] +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[AND]], 3 +; CHECK-NEXT: ret i1 [[CMP]] +; + %s1 = select i1 %x, i8 12, i8 3 + %s2 = select i1 %y, i8 12, i8 3 + %and = and i8 %s1, %s2 + %cmp = icmp eq i8 %and, 3 + ret i1 %cmp +} -- 2.7.4