1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; This test ensures that InstCombine does not distribute And over Xor
5 ; using simplifications involving undef.
7 define zeroext i1 @foo(i32 %arg) {
10 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[ARG:%.*]], 37
11 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB_THEN:%.*]], label [[BB_ELSE:%.*]]
13 ; CHECK-NEXT: call void @bar()
14 ; CHECK-NEXT: br label [[BB_EXIT:%.*]]
16 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[ARG]], 17
17 ; CHECK-NEXT: br label [[BB_EXIT]]
19 ; CHECK-NEXT: [[PHI1:%.*]] = phi i1 [ [[CMP2]], [[BB_ELSE]] ], [ undef, [[BB_THEN]] ]
20 ; CHECK-NEXT: [[XOR1:%.*]] = xor i1 [[CMP1]], true
21 ; CHECK-NEXT: [[AND1:%.*]] = and i1 [[PHI1]], [[XOR1]]
22 ; CHECK-NEXT: ret i1 [[AND1]]
26 %cmp1 = icmp eq i32 %arg, 37
27 br i1 %cmp1, label %bb_then, label %bb_else
34 %cmp2 = icmp slt i32 %arg, 17
38 %phi1 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
39 %xor1 = xor i1 %cmp1, true
40 %and1 = and i1 %phi1, %xor1
44 define zeroext i1 @foo_logical(i32 %arg) {
45 ; CHECK-LABEL: @foo_logical(
47 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[ARG:%.*]], 37
48 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB_THEN:%.*]], label [[BB_ELSE:%.*]]
50 ; CHECK-NEXT: call void @bar()
51 ; CHECK-NEXT: br label [[BB_EXIT:%.*]]
53 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[ARG]], 17
54 ; CHECK-NEXT: br label [[BB_EXIT]]
56 ; CHECK-NEXT: [[PHI1:%.*]] = phi i1 [ [[CMP2]], [[BB_ELSE]] ], [ undef, [[BB_THEN]] ]
57 ; CHECK-NEXT: [[XOR1:%.*]] = xor i1 [[CMP1]], true
58 ; CHECK-NEXT: [[AND1:%.*]] = select i1 [[PHI1]], i1 [[XOR1]], i1 false
59 ; CHECK-NEXT: ret i1 [[AND1]]
63 %cmp1 = icmp eq i32 %arg, 37
64 br i1 %cmp1, label %bb_then, label %bb_else
71 %cmp2 = icmp slt i32 %arg, 17
75 %phi1 = phi i1 [ %cmp2, %bb_else ], [ undef, %bb_then ]
76 %xor1 = xor i1 %cmp1, true
77 %and1 = select i1 %phi1, i1 %xor1, i1 false