From e50b4ea8be0bdd48fb1ab6b9ab659ae02eaaa318 Mon Sep 17 00:00:00 2001 From: Zhongyunde Date: Tue, 25 Apr 2023 21:39:06 +0800 Subject: [PATCH] [tests] precommit tests for D148986 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149115 --- .../Transforms/InstCombine/select-ctlz-to-cttz.ll | 1 + llvm/test/Transforms/InstSimplify/select_or_and.ll | 83 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll b/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll index 2a210d6..7b7e7c7 100644 --- a/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll +++ b/llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll @@ -141,6 +141,7 @@ define i32 @select_clz_to_ctz_wrong_sub(i32 %a) { ret i32 %cond } +; TODO: https://alive2.llvm.org/ce/z/X6QjcB define i64 @select_clz_to_ctz_i64_wrong_xor(i64 %a) { ; CHECK-LABEL: @select_clz_to_ctz_i64_wrong_xor( ; CHECK-NEXT: [[SUB:%.*]] = sub i64 0, [[A:%.*]] diff --git a/llvm/test/Transforms/InstSimplify/select_or_and.ll b/llvm/test/Transforms/InstSimplify/select_or_and.ll index 2188d3f..63476e2 100644 --- a/llvm/test/Transforms/InstSimplify/select_or_and.ll +++ b/llvm/test/Transforms/InstSimplify/select_or_and.ll @@ -191,3 +191,86 @@ define i32 @select_and_not_3(i32 %x, i32 %y) { %ret = select i1 %cmp, i32 %y, i32 %and ret i32 %ret } + +; TODO: https://alive2.llvm.org/ce/z/1ILbih +define i32 @select_icmp_and_eq(i32 %a, i32 %b) { +; CHECK-LABEL: @select_icmp_and_eq( +; CHECK-NEXT: [[AND:%.*]] = and i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[AND]], -1 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[A]], i32 -1 +; CHECK-NEXT: ret i32 [[COND]] +; + %and = and i32 %a, %b + %tobool = icmp eq i32 %and, -1 + %cond = select i1 %tobool, i32 %a, i32 -1 + ret i32 %cond +} + +; https://alive2.llvm.org/ce/z/hSyCuR +define i32 @select_icmp_or_eq(i32 %a, i32 %b) { +; CHECK-LABEL: @select_icmp_or_eq( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[OR]], 0 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[A]], i32 0 +; CHECK-NEXT: ret i32 [[COND]] +; + %or = or i32 %a, %b + %tobool = icmp eq i32 %or, 0 + %cond = select i1 %tobool, i32 %a, i32 0 + ret i32 %cond +} + +define i32 @select_icmp_or_eq_commuted(i32 %a, i32 %b) { +; CHECK-LABEL: @select_icmp_or_eq_commuted( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[OR]], 0 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[B]], i32 0 +; CHECK-NEXT: ret i32 [[COND]] +; + %or = or i32 %a, %b + %tobool = icmp eq i32 %or, 0 + %cond = select i1 %tobool, i32 %b, i32 0 + ret i32 %cond +} + +; https://alive2.llvm.org/ce/z/S_pQek +define <2 x i16> @select_icmp_or_eq_vec(<2 x i16> %a, <2 x i16> %b) { +; CHECK-LABEL: @select_icmp_or_eq_vec( +; CHECK-NEXT: [[OR:%.*]] = or <2 x i16> [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq <2 x i16> [[OR]], zeroinitializer +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[TOBOOL]], <2 x i16> [[A]], <2 x i16> zeroinitializer +; CHECK-NEXT: ret <2 x i16> [[COND]] +; + %or = or <2 x i16> %a, %b + %tobool = icmp eq <2 x i16> %or, + %cond = select <2 x i1> %tobool, <2 x i16> %a, <2 x i16> zeroinitializer + ret <2 x i16> %cond +} + +; The ne will also be matched +define i32 @select_icmp_or_ne(i32 %a, i32 %b) { +; CHECK-LABEL: @select_icmp_or_ne( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[OR]], 0 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 0, i32 [[A]] +; CHECK-NEXT: ret i32 [[COND]] +; + %or = or i32 %a, %b + %tobool = icmp ne i32 %or, 0 + %cond = select i1 %tobool, i32 0, i32 %a + ret i32 %cond +} + +; Negative test: Incorrect const value for icmp +define i32 @select_icmp_or_eq_incorrect_const(i32 %a, i32 %b) { +; CHECK-LABEL: @select_icmp_or_eq_incorrect_const( +; CHECK-NEXT: [[OR:%.*]] = or i32 [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[OR]], -1 +; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 [[A]], i32 0 +; CHECK-NEXT: ret i32 [[COND]] +; + %or = or i32 %a, %b + %tobool = icmp eq i32 %or, -1 + %cond = select i1 %tobool, i32 %a, i32 0 + ret i32 %cond +} -- 2.7.4