; 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) {
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
+}