1; RUN: opt -S -instcombine < %s | FileCheck %s 2 3declare void @foo() 4 5define void @test1(i32 %a, i32 %b) nounwind { 6 %1 = icmp slt i32 %a, 0 7 %2 = icmp slt i32 %b, 0 8 %or.cond = or i1 %1, %2 9 br i1 %or.cond, label %if.then, label %if.end 10 11; CHECK-LABEL: @test1( 12; CHECK-NEXT: %1 = or i32 %a, %b 13; CHECK-NEXT: %2 = icmp slt i32 %1, 0 14; CHECK-NEXT: br 15 16if.then: 17 tail call void @foo() nounwind 18 ret void 19 20if.end: 21 ret void 22} 23 24define void @test2(i32 %a, i32 %b) nounwind { 25 %1 = icmp sgt i32 %a, -1 26 %2 = icmp sgt i32 %b, -1 27 %or.cond = or i1 %1, %2 28 br i1 %or.cond, label %if.then, label %if.end 29 30; CHECK-LABEL: @test2( 31; CHECK-NEXT: %1 = and i32 %a, %b 32; CHECK-NEXT: %2 = icmp sgt i32 %1, -1 33; CHECK-NEXT: br 34 35if.then: 36 tail call void @foo() nounwind 37 ret void 38 39if.end: 40 ret void 41} 42 43define void @test3(i32 %a, i32 %b) nounwind { 44 %1 = icmp slt i32 %a, 0 45 %2 = icmp slt i32 %b, 0 46 %or.cond = and i1 %1, %2 47 br i1 %or.cond, label %if.then, label %if.end 48 49; CHECK-LABEL: @test3( 50; CHECK-NEXT: %1 = and i32 %a, %b 51; CHECK-NEXT: %2 = icmp slt i32 %1, 0 52; CHECK-NEXT: br 53 54if.then: 55 tail call void @foo() nounwind 56 ret void 57 58if.end: 59 ret void 60} 61 62define void @test4(i32 %a, i32 %b) nounwind { 63 %1 = icmp sgt i32 %a, -1 64 %2 = icmp sgt i32 %b, -1 65 %or.cond = and i1 %1, %2 66 br i1 %or.cond, label %if.then, label %if.end 67 68; CHECK-LABEL: @test4( 69; CHECK-NEXT: %1 = or i32 %a, %b 70; CHECK-NEXT: %2 = icmp sgt i32 %1, -1 71; CHECK-NEXT: br 72 73if.then: 74 tail call void @foo() nounwind 75 ret void 76 77if.end: 78 ret void 79} 80 81define void @test5(i32 %a) nounwind { 82 %and = and i32 %a, 134217728 83 %1 = icmp eq i32 %and, 0 84 %2 = icmp sgt i32 %a, -1 85 %or.cond = and i1 %1, %2 86 br i1 %or.cond, label %if.then, label %if.end 87 88; CHECK-LABEL: @test5( 89; CHECK-NEXT: %1 = and i32 %a, -2013265920 90; CHECK-NEXT: %2 = icmp eq i32 %1, 0 91; CHECK-NEXT: br i1 %2, label %if.then, label %if.end 92 93if.then: 94 tail call void @foo() nounwind 95 ret void 96 97if.end: 98 ret void 99} 100 101define void @test6(i32 %a) nounwind { 102 %1 = icmp sgt i32 %a, -1 103 %and = and i32 %a, 134217728 104 %2 = icmp eq i32 %and, 0 105 %or.cond = and i1 %1, %2 106 br i1 %or.cond, label %if.then, label %if.end 107 108; CHECK-LABEL: @test6( 109; CHECK-NEXT: %1 = and i32 %a, -2013265920 110; CHECK-NEXT: %2 = icmp eq i32 %1, 0 111; CHECK-NEXT: br i1 %2, label %if.then, label %if.end 112 113if.then: 114 tail call void @foo() nounwind 115 ret void 116 117if.end: 118 ret void 119} 120 121define void @test7(i32 %a) nounwind { 122 %and = and i32 %a, 134217728 123 %1 = icmp ne i32 %and, 0 124 %2 = icmp slt i32 %a, 0 125 %or.cond = or i1 %1, %2 126 br i1 %or.cond, label %if.then, label %if.end 127 128; CHECK-LABEL: @test7( 129; CHECK-NEXT: %1 = and i32 %a, -2013265920 130; CHECK-NEXT: %2 = icmp eq i32 %1, 0 131; CHECK-NEXT: br i1 %2, label %if.end, label %if.the 132 133if.then: 134 tail call void @foo() nounwind 135 ret void 136 137if.end: 138 ret void 139} 140 141define void @test8(i32 %a) nounwind { 142 %1 = icmp slt i32 %a, 0 143 %and = and i32 %a, 134217728 144 %2 = icmp ne i32 %and, 0 145 %or.cond = or i1 %1, %2 146 br i1 %or.cond, label %if.then, label %if.end 147 148; CHECK-LABEL: @test8( 149; CHECK-NEXT: %1 = and i32 %a, -2013265920 150; CHECK-NEXT: %2 = icmp eq i32 %1, 0 151; CHECK-NEXT: br i1 %2, label %if.end, label %if.the 152 153if.then: 154 tail call void @foo() nounwind 155 ret void 156 157if.end: 158 ret void 159} 160 161define void @test9(i32 %a) nounwind { 162 %1 = and i32 %a, 1073741824 163 %2 = icmp ne i32 %1, 0 164 %3 = icmp sgt i32 %a, -1 165 %or.cond = and i1 %2, %3 166 br i1 %or.cond, label %if.then, label %if.end 167 168; CHECK-LABEL: @test9( 169; CHECK-NEXT: %1 = and i32 %a, -1073741824 170; CHECK-NEXT: %2 = icmp eq i32 %1, 1073741824 171; CHECK-NEXT: br i1 %2, label %if.then, label %if.end 172 173if.then: 174 tail call void @foo() nounwind 175 ret void 176 177if.end: 178 ret void 179} 180 181define void @test10(i32 %a) nounwind { 182 %1 = and i32 %a, 2 183 %2 = icmp eq i32 %1, 0 184 %3 = icmp ult i32 %a, 4 185 %or.cond = and i1 %2, %3 186 br i1 %or.cond, label %if.then, label %if.end 187 188; CHECK-LABEL: @test10( 189; CHECK-NEXT: %1 = icmp ult i32 %a, 2 190; CHECK-NEXT: br i1 %1, label %if.then, label %if.end 191 192if.then: 193 tail call void @foo() nounwind 194 ret void 195 196if.end: 197 ret void 198} 199 200define void @test11(i32 %a) nounwind { 201 %1 = and i32 %a, 2 202 %2 = icmp ne i32 %1, 0 203 %3 = icmp ugt i32 %a, 3 204 %or.cond = or i1 %2, %3 205 br i1 %or.cond, label %if.then, label %if.end 206 207; CHECK-LABEL: @test11( 208; CHECK-NEXT: %1 = icmp ugt i32 %a, 1 209; CHECK-NEXT: br i1 %1, label %if.then, label %if.end 210 211if.then: 212 tail call void @foo() nounwind 213 ret void 214 215if.end: 216 ret void 217} 218