1; RUN: opt < %s -instcombine -S | FileCheck %s
2;
3; This test makes sure that InstCombine does not replace the sequence of
4; xor/sub instruction followed by cmp instruction into a single cmp instruction
5; if there is more than one use of xor/sub.
6
7define zeroext i1 @test1(i32 %lhs, i32 %rhs) {
8; CHECK-LABEL: @test1(
9; CHECK-NEXT: %xor = xor i32 %lhs, 5
10; CHECK-NEXT: %cmp1 = icmp eq i32 %xor, 10
11
12  %xor = xor i32 %lhs, 5
13  %cmp1 = icmp eq i32 %xor, 10
14  %cmp2 = icmp eq i32 %xor, %rhs
15  %sel = or i1 %cmp1, %cmp2
16  ret i1 %sel
17}
18
19define zeroext i1 @test2(i32 %lhs, i32 %rhs) {
20; CHECK-LABEL: @test2(
21; CHECK-NEXT: %xor = xor i32 %lhs, %rhs
22; CHECK-NEXT: %cmp1 = icmp eq i32 %xor, 0
23
24  %xor = xor i32 %lhs, %rhs
25  %cmp1 = icmp eq i32 %xor, 0
26  %cmp2 = icmp eq i32 %xor, 32
27  %sel = xor i1 %cmp1, %cmp2
28  ret i1 %sel
29}
30
31define zeroext i1 @test3(i32 %lhs, i32 %rhs) {
32; CHECK-LABEL: @test3(
33; CHECK-NEXT: %sub = sub nsw i32 %lhs, %rhs
34; CHECK-NEXT: %cmp1 = icmp eq i32 %sub, 0
35
36  %sub = sub nsw i32 %lhs, %rhs
37  %cmp1 = icmp eq i32 %sub, 0
38  %cmp2 = icmp eq i32 %sub, 31
39  %sel = or i1 %cmp1, %cmp2
40  ret i1 %sel
41}
42