1 ; NOTE: Assertions have been autogenerated by update_test_checks.py
2 ; RUN: opt -S -instsimplify < %s | FileCheck %s
4 define i1 @test(i32 %a) {
9 %and = and i32 %a, %rhs
10 %res = icmp eq i32 %and, 1
14 define i1 @test2(i32 %a) {
15 ; CHECK-LABEL: @test2(
19 %and = and i32 %a, %rhs
20 %res = icmp eq i32 %and, 1
24 define i1 @test3(i32 %a) {
25 ; CHECK-LABEL: @test3(
29 %and = and i32 %a, %rhs
30 %res = icmp eq i32 %and, 1
34 @B = external global i32
35 declare void @llvm.assume(i1)
37 ; Known bits without a constant
38 define 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
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)
52 %and = and i32 %a, %rhs
53 %res = icmp eq i32 %and, 1
57 ; Negative test - even number
58 define 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]]
66 %and = and i32 %a, %rhs
67 %res = icmp eq i32 %and, 1
71 define i1 @test6(i32 %a) {
72 ; CHECK-LABEL: @test6(
76 %and = and i32 %lhs, %a
77 %res = icmp eq i32 %and, 1