From e6cd157407a24f7be1c15dbf949bac98400ff96d Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 23 Nov 2021 08:55:49 -0500 Subject: [PATCH] [InstCombine] add tests for logical select; NFC --- llvm/test/Transforms/InstCombine/logical-select.ll | 55 +++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/llvm/test/Transforms/InstCombine/logical-select.ll b/llvm/test/Transforms/InstCombine/logical-select.ll index 1ec5b30..459e1b1 100644 --- a/llvm/test/Transforms/InstCombine/logical-select.ll +++ b/llvm/test/Transforms/InstCombine/logical-select.ll @@ -1,6 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s +declare void @use(i8) define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) { ; CHECK-LABEL: @foo( @@ -388,7 +389,7 @@ define i1 @bools_logical(i1 %a, i1 %b, i1 %c) { ret i1 %or } -; Form a select if we know we can get replace 2 simple logic ops. +; Form a select if we know we can replace 2 simple logic ops. define i1 @bools_multi_uses1(i1 %a, i1 %b, i1 %c) { ; CHECK-LABEL: @bools_multi_uses1( @@ -827,3 +828,55 @@ define i64 @bitcast_int_scalar_cond(<2 x i1> %b, i64 %c, i64 %d) { %r = or i64 %t11, %t12 ret i64 %r } + +; TODO: +; Peek through bitcasts and sexts to find negated bool condition. + +define <1 x i6> @bitcast_sext_cond(<2 x i1> %cmp, <1 x i6> %a, <1 x i6> %b) { +; CHECK-LABEL: @bitcast_sext_cond( +; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP:%.*]] to <2 x i3> +; CHECK-NEXT: [[BC1:%.*]] = bitcast <2 x i3> [[SEXT]] to <1 x i6> +; CHECK-NEXT: [[NEG:%.*]] = xor <2 x i1> [[CMP]], +; CHECK-NEXT: [[SEXT2:%.*]] = sext <2 x i1> [[NEG]] to <2 x i3> +; CHECK-NEXT: [[BC2:%.*]] = bitcast <2 x i3> [[SEXT2]] to <1 x i6> +; CHECK-NEXT: [[AND1:%.*]] = and <1 x i6> [[BC1]], [[A:%.*]] +; CHECK-NEXT: [[AND2:%.*]] = and <1 x i6> [[BC2]], [[B:%.*]] +; CHECK-NEXT: [[OR:%.*]] = or <1 x i6> [[AND1]], [[AND2]] +; CHECK-NEXT: ret <1 x i6> [[OR]] +; + %sext = sext <2 x i1> %cmp to <2 x i3> + %bc1 = bitcast <2 x i3> %sext to <1 x i6> + %neg = xor <2 x i1> %cmp, + %sext2 = sext <2 x i1> %neg to <2 x i3> + %bc2 = bitcast <2 x i3> %sext2 to <1 x i6> + %and1 = and <1 x i6> %bc1, %a + %and2 = and <1 x i6> %bc2, %b + %or = or <1 x i6> %and1, %and2 + ret <1 x i6> %or +} + +; TODO: +; Extra uses may prevent other transforms from creating the canonical patterns. + +define i8 @sext_cond_extra_uses(i1 %cmp, i8 %a, i8 %b) { +; CHECK-LABEL: @sext_cond_extra_uses( +; CHECK-NEXT: [[NEG:%.*]] = xor i1 [[CMP:%.*]], true +; CHECK-NEXT: [[SEXT1:%.*]] = sext i1 [[CMP]] to i8 +; CHECK-NEXT: call void @use(i8 [[SEXT1]]) +; CHECK-NEXT: [[SEXT2:%.*]] = sext i1 [[NEG]] to i8 +; CHECK-NEXT: call void @use(i8 [[SEXT2]]) +; CHECK-NEXT: [[AND1:%.*]] = and i8 [[SEXT1]], [[A:%.*]] +; CHECK-NEXT: [[AND2:%.*]] = and i8 [[SEXT2]], [[B:%.*]] +; CHECK-NEXT: [[OR:%.*]] = or i8 [[AND1]], [[AND2]] +; CHECK-NEXT: ret i8 [[OR]] +; + %neg = xor i1 %cmp, -1 + %sext1 = sext i1 %cmp to i8 + call void @use(i8 %sext1) + %sext2 = sext i1 %neg to i8 + call void @use(i8 %sext2) + %and1 = and i8 %sext1, %a + %and2 = and i8 %sext2, %b + %or = or i8 %and1, %and2 + ret i8 %or +} -- 2.7.4