[llvm] aa887ff - [InstCombine] add test for branch on logical-and; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 14:39:37 PDT 2022


Author: Sanjay Patel
Date: 2022-10-31T17:39:29-04:00
New Revision: aa887ff3f43aeaeb76d6be176d0ed67eb414eff8

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

LOG: [InstCombine] add test for branch on logical-and; NFC

More coverage for the change 115d2f69a515cd756fa51 as
suggested in post-commit feedback.

Given that the transform is canonicalized with another
'not' op, we should adjust the use checks and create
that form directly.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/branch.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/branch.ll b/llvm/test/Transforms/InstCombine/branch.ll
index f90c8a251207..2961dec50adf 100644
--- a/llvm/test/Transforms/InstCombine/branch.ll
+++ b/llvm/test/Transforms/InstCombine/branch.ll
@@ -1,6 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
 
+declare void @use(i1)
+
 ; Check that we fold the condition of branches of the
 ; form: br <condition> dest1, dest2, where dest1 == dest2.
 define i32 @test(i32 %x) {
@@ -186,3 +188,56 @@ t:
 f:
   ret i32 3
 }
+
+define i32 @logical_and_not_use1(i1 %x, i1 %y) {
+; CHECK-LABEL: @logical_and_not_use1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    call void @use(i1 [[NOTY]])
+; CHECK-NEXT:    [[NOT_X:%.*]] = xor i1 [[X:%.*]], true
+; CHECK-NEXT:    [[TMP0:%.*]] = select i1 [[NOT_X]], i1 true, i1 [[Y]]
+; CHECK-NEXT:    br i1 [[TMP0]], label [[F:%.*]], label [[T:%.*]]
+; CHECK:       t:
+; CHECK-NEXT:    ret i32 42
+; CHECK:       f:
+; CHECK-NEXT:    ret i32 3
+;
+entry:
+  %noty = xor i1 %y, true
+  call void @use(i1 %noty)
+  %and = select i1 %x, i1 %noty, i1 false
+  br i1 %and, label %t, label %f
+
+t:
+  ret i32 42
+
+f:
+  ret i32 3
+}
+
+; negative test
+
+define i32 @logical_and_not_use2(i1 %x, i1 %y) {
+; CHECK-LABEL: @logical_and_not_use2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[NOTY:%.*]] = xor i1 [[Y:%.*]], true
+; CHECK-NEXT:    [[AND:%.*]] = select i1 [[X:%.*]], i1 [[NOTY]], i1 false
+; CHECK-NEXT:    call void @use(i1 [[AND]])
+; CHECK-NEXT:    br i1 [[AND]], label [[T:%.*]], label [[F:%.*]]
+; CHECK:       t:
+; CHECK-NEXT:    ret i32 42
+; CHECK:       f:
+; CHECK-NEXT:    ret i32 3
+;
+entry:
+  %noty = xor i1 %y, true
+  %and = select i1 %x, i1 %noty, i1 false
+  call void @use(i1 %and)
+  br i1 %and, label %t, label %f
+
+t:
+  ret i32 42
+
+f:
+  ret i32 3
+}


        


More information about the llvm-commits mailing list