• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by update_test_checks.py
2; RUN: opt -S -instsimplify < %s | FileCheck %s
3
4define i1 @test(i32 %a) {
5; CHECK-LABEL: @test(
6; CHECK:         ret i1 false
7;
8  %rhs = add i32 %a, -1
9  %and = and i32 %a, %rhs
10  %res = icmp eq i32 %and, 1
11  ret i1 %res
12}
13
14define i1 @test2(i32 %a) {
15; CHECK-LABEL: @test2(
16; CHECK:         ret i1 false
17;
18  %rhs = add i32 %a, 1
19  %and = and i32 %a, %rhs
20  %res = icmp eq i32 %and, 1
21  ret i1 %res
22}
23
24define i1 @test3(i32 %a) {
25; CHECK-LABEL: @test3(
26; CHECK:         ret i1 false
27;
28  %rhs = add i32 %a, 7
29  %and = and i32 %a, %rhs
30  %res = icmp eq i32 %and, 1
31  ret i1 %res
32}
33
34@B = external global i32
35declare void @llvm.assume(i1)
36
37; Known bits without a constant
38define i1 @test4(i32 %a) {
39; CHECK-LABEL: @test4(
40; CHECK:         [[B:%.*]] = load i32, i32* @B
41; CHECK-NEXT:    [[B_AND:%.*]] = and i32 [[B]], 1
42; CHECK-NEXT:    [[B_CND:%.*]] = icmp eq i32 [[B_AND]], 1
43; CHECK-NEXT:    call void @llvm.assume(i1 [[B_CND]])
44; CHECK-NEXT:    ret i1 false
45;
46  %b = load i32, i32* @B
47  %b.and = and i32 %b, 1
48  %b.cnd = icmp eq i32 %b.and, 1
49  call void @llvm.assume(i1 %b.cnd)
50
51  %rhs = add i32 %a, %b
52  %and = and i32 %a, %rhs
53  %res = icmp eq i32 %and, 1
54  ret i1 %res
55}
56
57; Negative test - even number
58define i1 @test5(i32 %a) {
59; CHECK-LABEL: @test5(
60; CHECK:         [[RHS:%.*]] = add i32 %a, 2
61; CHECK-NEXT:    [[AND:%.*]] = and i32 %a, [[RHS]]
62; CHECK-NEXT:    [[RES:%.*]] = icmp eq i32 [[AND]], 1
63; CHECK-NEXT:    ret i1 [[RES]]
64;
65  %rhs = add i32 %a, 2
66  %and = and i32 %a, %rhs
67  %res = icmp eq i32 %and, 1
68  ret i1 %res
69}
70
71define i1 @test6(i32 %a) {
72; CHECK-LABEL: @test6(
73; CHECK:         ret i1 false
74;
75  %lhs = add i32 %a, -1
76  %and = and i32 %lhs, %a
77  %res = icmp eq i32 %and, 1
78  ret i1 %res
79}
80