xref: /llvm-project/llvm/test/Transforms/InstSimplify/pr49495.ll (revision 04b944e23050e4e0c6ee983cc9bc17740315ea4f)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3
4; The first comparison (a != b) should not be dropped
5define i1 @test1(ptr %a, ptr %b) {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:    [[COND1:%.*]] = icmp ne ptr [[A:%.*]], [[B:%.*]]
8; CHECK-NEXT:    [[A2:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 -1
9; CHECK-NEXT:    [[COND2:%.*]] = icmp ugt ptr [[A2]], [[B]]
10; CHECK-NEXT:    [[RES:%.*]] = select i1 [[COND1]], i1 [[COND2]], i1 false
11; CHECK-NEXT:    ret i1 [[RES]]
12;
13  %cond1 = icmp ne ptr %a, %b
14  %a2 = getelementptr inbounds i8, ptr %a, i64 -1
15  %cond2 = icmp ugt ptr %a2, %b
16  %res = select i1 %cond1, i1 %cond2, i1 false
17  ret i1 %res
18}
19
20; The first comparison (a != b) should not be dropped
21define i1 @test2(i32 %a, i32 %b) {
22; CHECK-LABEL: @test2(
23; CHECK-NEXT:    [[COND1:%.*]] = icmp ne i32 [[A:%.*]], [[B:%.*]]
24; CHECK-NEXT:    [[A2:%.*]] = add nuw i32 [[A]], 1
25; CHECK-NEXT:    [[COND2:%.*]] = icmp ult i32 [[A2]], [[B]]
26; CHECK-NEXT:    [[RES:%.*]] = select i1 [[COND1]], i1 [[COND2]], i1 false
27; CHECK-NEXT:    ret i1 [[RES]]
28;
29  %cond1 = icmp ne i32 %a, %b
30  %a2 = add nuw i32 %a, 1
31  %cond2 = icmp ult i32 %a2, %b
32  %res = select i1 %cond1, i1 %cond2, i1 false
33  ret i1 %res
34}
35