1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
4 define i1 @test1(i32 %a) {
6 ; CHECK-NEXT: ret i1 false
9 %and = and i32 %a, %rhs
10 %res = icmp eq i32 %and, 1
14 define i1 @test1v(<2 x i32> %a) {
15 ; CHECK-LABEL: @test1v(
16 ; CHECK-NEXT: ret i1 false
18 %rhs = add <2 x i32> %a, <i32 -1, i32 0>
19 %and = and <2 x i32> %a, %rhs
20 %ext = extractelement <2 x i32> %and, i32 0
21 %res = icmp eq i32 %ext, 1
25 define i1 @test2(i32 %a) {
26 ; CHECK-LABEL: @test2(
27 ; CHECK-NEXT: ret i1 false
30 %and = and i32 %a, %rhs
31 %res = icmp eq i32 %and, 1
35 define i1 @test2v(<2 x i32> %a) {
36 ; CHECK-LABEL: @test2v(
37 ; CHECK-NEXT: ret i1 false
39 %rhs = add <2 x i32> %a, <i32 0, i32 1>
40 %and = and <2 x i32> %a, %rhs
41 %ext = extractelement <2 x i32> %and, i32 1
42 %res = icmp eq i32 %ext, 1
46 define i1 @test3(i32 %a) {
47 ; CHECK-LABEL: @test3(
48 ; CHECK-NEXT: ret i1 false
51 %and = and i32 %a, %rhs
52 %res = icmp eq i32 %and, 1
56 define i1 @test3v(<2 x i32> %a) {
57 ; CHECK-LABEL: @test3v(
58 ; CHECK-NEXT: ret i1 false
60 %rhs = add <2 x i32> %a, <i32 7, i32 0>
61 %and = and <2 x i32> %a, %rhs
62 %ext = extractelement <2 x i32> %and, i32 0
63 %res = icmp eq i32 %ext, 1
67 @B = external global i32
68 declare void @llvm.assume(i1)
70 ; Known bits without a constant
71 define i1 @test4(i32 %a) {
72 ; CHECK-LABEL: @test4(
73 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr @B, align 4
74 ; CHECK-NEXT: [[B_AND:%.*]] = and i32 [[B]], 1
75 ; CHECK-NEXT: [[B_CND:%.*]] = icmp eq i32 [[B_AND]], 1
76 ; CHECK-NEXT: call void @llvm.assume(i1 [[B_CND]])
77 ; CHECK-NEXT: ret i1 false
80 %b.and = and i32 %b, 1
81 %b.cnd = icmp eq i32 %b.and, 1
82 call void @llvm.assume(i1 %b.cnd)
85 %and = and i32 %a, %rhs
86 %res = icmp eq i32 %and, 1
90 ; Negative test - even number
91 define i1 @test5(i32 %a) {
92 ; CHECK-LABEL: @test5(
93 ; CHECK-NEXT: [[RHS:%.*]] = add i32 [[A:%.*]], 2
94 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[A]], [[RHS]]
95 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[AND]], 1
96 ; CHECK-NEXT: ret i1 [[RES]]
99 %and = and i32 %a, %rhs
100 %res = icmp eq i32 %and, 1
104 define i1 @test5v(<2 x i32> %a) {
105 ; CHECK-LABEL: @test5v(
106 ; CHECK-NEXT: [[RHS:%.*]] = add <2 x i32> [[A:%.*]], <i32 2, i32 0>
107 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[A]], [[RHS]]
108 ; CHECK-NEXT: [[EXT:%.*]] = extractelement <2 x i32> [[AND]], i32 1
109 ; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[EXT]], 1
110 ; CHECK-NEXT: ret i1 [[RES]]
112 %rhs = add <2 x i32> %a, <i32 2, i32 0>
113 %and = and <2 x i32> %a, %rhs
114 %ext = extractelement <2 x i32> %and, i32 1
115 %res = icmp eq i32 %ext, 1
119 define i1 @test6(i32 %a) {
120 ; CHECK-LABEL: @test6(
121 ; CHECK-NEXT: ret i1 false
123 %lhs = add i32 %a, -1
124 %and = and i32 %lhs, %a
125 %res = icmp eq i32 %and, 1
129 define i1 @test6v(<2 x i32> %a) {
130 ; CHECK-LABEL: @test6v(
131 ; CHECK-NEXT: ret i1 false
133 %lhs = add <2 x i32> %a, <i32 0, i32 -1>
134 %and = and <2 x i32> %lhs, %a
135 %ext = extractelement <2 x i32> %and, i32 1
136 %res = icmp eq i32 %ext, 1