[llvm] 6a7d5d3 - Precommit tests for D145157.

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 09:10:43 PST 2023


Author: Paul Walker
Date: 2023-03-03T17:09:39Z
New Revision: 6a7d5d37bc39f4195404a86ff08f0c2db21d49f0

URL: https://github.com/llvm/llvm-project/commit/6a7d5d37bc39f4195404a86ff08f0c2db21d49f0
DIFF: https://github.com/llvm/llvm-project/commit/6a7d5d37bc39f4195404a86ff08f0c2db21d49f0.diff

LOG: Precommit tests for D145157.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/logical-select.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/logical-select.ll b/llvm/test/Transforms/InstCombine/logical-select.ll
index 5537fdcca53a..14782732d866 100644
--- a/llvm/test/Transforms/InstCombine/logical-select.ll
+++ b/llvm/test/Transforms/InstCombine/logical-select.ll
@@ -1,8 +1,11 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 
+declare i1 @gen()
+
 declare void @use(i8)
 declare void @use1(i1)
+declare void @use2(<2 x i1>)
 
 define i32 @foo(i32 %a, i32 %b, i32 %c, i32 %d) {
 ; CHECK-LABEL: @foo(
@@ -1121,3 +1124,197 @@ define i1 @not_d_bools_negative_use2(i1 %c, i1 %x, i1 %y) {
   call void @use1(i1 %and1)
   ret i1 %r
 }
+
+; A & (~C | B)
+define i1 @test1(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true
+; CHECK-NEXT:    [[OR:%.*]] = or i1 [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A:%.*]], i1 [[OR]], i1 false
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %not = xor i1 %c, true
+  %or = or i1 %not, %b
+  %and = select i1 %a, i1 %or, i1 zeroinitializer
+  ret i1 %and
+}
+
+; As test1 but with C=A
+; A & (~A | B) --> A & B
+define i1 @test1_variant1(i1 %a, i1 %b) {
+; CHECK-LABEL: @test1_variant1(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[OR:%.*]] = or i1 [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A]], i1 [[OR]], i1 false
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %not = xor i1 %a, true
+  %or = or i1 %not, %b
+  %and = select i1 %a, i1 %or, i1 zeroinitializer
+  ret i1 %and
+}
+
+; As test1_variant1 but operating on vectors
+; A & (~A | B) --> A & B
+define <2 x i1> @test1_variant2(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @test1_variant2(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[OR:%.*]] = or <2 x i1> [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[A]], <2 x i1> [[OR]], <2 x i1> zeroinitializer
+; CHECK-NEXT:    ret <2 x i1> [[AND]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %or = or <2 x i1> %not, %b
+  %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer
+  ret <2 x i1> %and
+}
+
+; As test1_variant1 but with "or" implemented as "select X, true, Y"
+; A & (~A | B) --> A & B
+define i1 @test1_variant3(i1 %a, i1 %b) {
+; CHECK-LABEL: @test1_variant3(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[OR:%.*]] = select i1 [[NOT]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A]], i1 [[OR]], i1 false
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %not = xor i1 %a, true
+  %or = select i1 %not, i1 true, i1 %b
+  %and = select i1 %a, i1 %or, i1 zeroinitializer
+  ret i1 %and
+}
+
+; As test1_variant3 but operating on vectors where each operand has other uses
+; A & (~A | B) --> A & B
+define <2 x i1> @test1_variant4(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @test1_variant4(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[NOT]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[B:%.*]]
+; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[A]], <2 x i1> [[OR]], <2 x i1> zeroinitializer
+; CHECK-NEXT:    call void @use2(<2 x i1> [[A]])
+; CHECK-NEXT:    call void @use2(<2 x i1> [[B]])
+; CHECK-NEXT:    call void @use2(<2 x i1> [[OR]])
+; CHECK-NEXT:    ret <2 x i1> [[AND]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %or = select <2 x i1> %not, <2 x i1> <i1 true, i1 true>, <2 x i1> %b
+  %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer
+  call void @use2(<2 x i1> %a)
+  call void @use2(<2 x i1> %b)
+  call void @use2(<2 x i1> %or)
+  ret <2 x i1> %and
+}
+
+; As test1_variant1 but with |'s operands swapped
+; A & (B | ~A) --> A & B
+define i1 @test1_variant5(i1 %a) {
+; CHECK-LABEL: @test1_variant5(
+; CHECK-NEXT:    [[B:%.*]] = call i1 @gen()
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[OR:%.*]] = or i1 [[B]], [[NOT]]
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[A]], i1 [[OR]], i1 false
+; CHECK-NEXT:    ret i1 [[AND]]
+;
+  %b = call i1 @gen()
+  %not = xor i1 %a, true
+  %or = or i1 %b, %not
+  %and = select i1 %a, i1 %or, i1 zeroinitializer
+  ret i1 %and
+}
+
+; A | (~C & B)
+define i1 @test2(i1 %a, i1 %b, i1 %c) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[C:%.*]], true
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[AND]]
+; CHECK-NEXT:    ret i1 [[OR]]
+;
+  %not = xor i1 %c, true
+  %and = and i1 %not, %b
+  %or = select i1 %a, i1 true, i1 %and
+  ret i1 %or
+}
+
+; As test2 but with C=A
+; A | (~A & B) --> A | B
+define i1 @test2_variant1(i1 %a, i1 %b) {
+; CHECK-LABEL: @test2_variant1(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A]], i1 true, i1 [[AND]]
+; CHECK-NEXT:    ret i1 [[OR]]
+;
+  %not = xor i1 %a, true
+  %and = and i1 %not, %b
+  %or = select i1 %a, i1 true, i1 %and
+  ret i1 %or
+}
+
+; As test2_variant1 but operating on vectors
+; A | (~A & B) --> A | B
+define <2 x i1> @test2_variant2(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @test2_variant2(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[AND:%.*]] = and <2 x i1> [[NOT]], [[B:%.*]]
+; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[A]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[AND]]
+; CHECK-NEXT:    ret <2 x i1> [[OR]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %and = and <2 x i1> %not, %b
+  %or = select <2 x i1> %a, <2 x i1> <i1 true, i1 true>, <2 x i1> %and
+  ret <2 x i1> %or
+}
+
+; As test2_variant1 but with "and" implemented as "select X, Y, false"
+; A | (~A & B) --> A | B
+define i1 @test2_variant3(i1 %a, i1 %b) {
+; CHECK-LABEL: @test2_variant3(
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[NOT]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A]], i1 true, i1 [[AND]]
+; CHECK-NEXT:    ret i1 [[OR]]
+;
+  %not = xor i1 %a, true
+  %and = select i1 %not, i1 %b, i1 false
+  %or = select i1 %a, i1 true, i1 %and
+  ret i1 %or
+}
+
+; As test2_variant3 but operating on vectors where each operand has other uses
+; A | (~A & B) --> A | B
+define <2 x i1> @test2_variant4(<2 x i1> %a, <2 x i1> %b) {
+; CHECK-LABEL: @test2_variant4(
+; CHECK-NEXT:    [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
+; CHECK-NEXT:    [[AND:%.*]] = select <2 x i1> [[NOT]], <2 x i1> [[B:%.*]], <2 x i1> zeroinitializer
+; CHECK-NEXT:    [[OR:%.*]] = select <2 x i1> [[A]], <2 x i1> <i1 true, i1 true>, <2 x i1> [[AND]]
+; CHECK-NEXT:    call void @use2(<2 x i1> [[A]])
+; CHECK-NEXT:    call void @use2(<2 x i1> [[B]])
+; CHECK-NEXT:    call void @use2(<2 x i1> [[AND]])
+; CHECK-NEXT:    ret <2 x i1> [[OR]]
+;
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %and = select <2 x i1> %not, <2 x i1> %b, <2 x i1> zeroinitializer
+  %or = select <2 x i1> %a, <2 x i1> <i1 true, i1 true>, <2 x i1> %and
+  call void @use2(<2 x i1> %a)
+  call void @use2(<2 x i1> %b)
+  call void @use2(<2 x i1> %and)
+  ret <2 x i1> %or
+}
+
+; As test2_variant1 but with &'s operands swapped
+; A | (B & ~A) --> A | B
+define i1 @test2_variant5(i1 %a) {
+; CHECK-LABEL: @test2_variant5(
+; CHECK-NEXT:    [[B:%.*]] = call i1 @gen()
+; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[A:%.*]], true
+; CHECK-NEXT:    [[AND:%.*]] = and i1 [[B]], [[NOT]]
+; CHECK-NEXT:    [[OR:%.*]] = select i1 [[A]], i1 true, i1 [[AND]]
+; CHECK-NEXT:    ret i1 [[OR]]
+;
+  %b = call i1 @gen()
+  %not = xor i1 %a, true
+  %and = and i1 %b, %not
+  %or = select i1 %a, i1 true, i1 %and
+  ret i1 %or
+}


        


More information about the llvm-commits mailing list