1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3 4@G1 = global i32 0 5@G2 = global i32 0 6 7define i1 @test0(i1 %A) { 8; CHECK-LABEL: @test0( 9; CHECK-NEXT: ret i1 %A 10; 11 %B = xor i1 %A, false 12 ret i1 %B 13} 14 15define i32 @test1(i32 %A) { 16; CHECK-LABEL: @test1( 17; CHECK-NEXT: ret i32 %A 18; 19 %B = xor i32 %A, 0 20 ret i32 %B 21} 22 23define i1 @test2(i1 %A) { 24; CHECK-LABEL: @test2( 25; CHECK-NEXT: ret i1 false 26; 27 %B = xor i1 %A, %A 28 ret i1 %B 29} 30 31define i32 @test3(i32 %A) { 32; CHECK-LABEL: @test3( 33; CHECK-NEXT: ret i32 0 34; 35 %B = xor i32 %A, %A 36 ret i32 %B 37} 38 39define i32 @test4(i32 %A) { 40; CHECK-LABEL: @test4( 41; CHECK-NEXT: ret i32 -1 42; 43 %NotA = xor i32 -1, %A 44 %B = xor i32 %A, %NotA 45 ret i32 %B 46} 47 48define i32 @test5(i32 %A) { 49; CHECK-LABEL: @test5( 50; CHECK-NEXT: [[TMP1:%.*]] = and i32 %A, -124 51; CHECK-NEXT: ret i32 [[TMP1]] 52; 53 %t1 = or i32 %A, 123 54 %r = xor i32 %t1, 123 55 ret i32 %r 56} 57 58define i8 @test6(i8 %A) { 59; CHECK-LABEL: @test6( 60; CHECK-NEXT: ret i8 %A 61; 62 %B = xor i8 %A, 17 63 %C = xor i8 %B, 17 64 ret i8 %C 65} 66 67define i32 @test7(i32 %A, i32 %B) { 68; CHECK-LABEL: @test7( 69; CHECK-NEXT: [[A1:%.*]] = and i32 %A, 7 70; CHECK-NEXT: [[B1:%.*]] = and i32 %B, 128 71; CHECK-NEXT: [[C11:%.*]] = or i32 [[A1]], [[B1]] 72; CHECK-NEXT: ret i32 [[C11]] 73; 74 %A1 = and i32 %A, 7 75 %B1 = and i32 %B, 128 76 %C1 = xor i32 %A1, %B1 77 ret i32 %C1 78} 79 80define i8 @test8(i1 %c) { 81; CHECK-LABEL: @test8( 82; CHECK-NEXT: br i1 %c, label %False, label %True 83; CHECK: True: 84; CHECK-NEXT: ret i8 1 85; CHECK: False: 86; CHECK-NEXT: ret i8 3 87; 88 %d = xor i1 %c, true 89 br i1 %d, label %True, label %False 90 91True: 92 ret i8 1 93 94False: 95 ret i8 3 96} 97 98define i1 @test9(i8 %A) { 99; CHECK-LABEL: @test9( 100; CHECK-NEXT: [[C:%.*]] = icmp eq i8 %A, 89 101; CHECK-NEXT: ret i1 [[C]] 102; 103 %B = xor i8 %A, 123 104 %C = icmp eq i8 %B, 34 105 ret i1 %C 106} 107 108define i8 @test10(i8 %A) { 109; CHECK-LABEL: @test10( 110; CHECK-NEXT: [[B:%.*]] = and i8 %A, 3 111; CHECK-NEXT: [[C1:%.*]] = or i8 [[B]], 4 112; CHECK-NEXT: ret i8 [[C1]] 113; 114 %B = and i8 %A, 3 115 %C = xor i8 %B, 4 116 ret i8 %C 117} 118 119define i8 @test11(i8 %A) { 120; CHECK-LABEL: @test11( 121; CHECK-NEXT: [[B:%.*]] = and i8 %A, -13 122; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[B]], 8 123; CHECK-NEXT: ret i8 [[TMP1]] 124; 125 %B = or i8 %A, 12 126 %C = xor i8 %B, 4 127 ret i8 %C 128} 129 130define i1 @test12(i8 %A) { 131; CHECK-LABEL: @test12( 132; CHECK-NEXT: [[C:%.*]] = icmp ne i8 %A, 4 133; CHECK-NEXT: ret i1 [[C]] 134; 135 %B = xor i8 %A, 4 136 %c = icmp ne i8 %B, 0 137 ret i1 %c 138} 139 140define i1 @test13(i8 %A, i8 %B) { 141; CHECK-LABEL: @test13( 142; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 %A, %B 143; CHECK-NEXT: ret i1 [[TMP1]] 144; 145 %C = icmp ult i8 %A, %B 146 %D = icmp ugt i8 %A, %B 147 %E = xor i1 %C, %D 148 ret i1 %E 149} 150 151define i1 @test14(i8 %A, i8 %B) { 152; CHECK-LABEL: @test14( 153; CHECK-NEXT: ret i1 true 154; 155 %C = icmp eq i8 %A, %B 156 %D = icmp ne i8 %B, %A 157 %E = xor i1 %C, %D 158 ret i1 %E 159} 160 161define i32 @test15(i32 %A) { 162; CHECK-LABEL: @test15( 163; CHECK-NEXT: [[C:%.*]] = sub i32 0, %A 164; CHECK-NEXT: ret i32 [[C]] 165; 166 %B = add i32 %A, -1 167 %C = xor i32 %B, -1 168 ret i32 %C 169} 170 171define i32 @test16(i32 %A) { 172; CHECK-LABEL: @test16( 173; CHECK-NEXT: [[C:%.*]] = sub i32 -124, %A 174; CHECK-NEXT: ret i32 [[C]] 175; 176 %B = add i32 %A, 123 177 %C = xor i32 %B, -1 178 ret i32 %C 179} 180 181define i32 @test17(i32 %A) { 182; CHECK-LABEL: @test17( 183; CHECK-NEXT: [[C:%.*]] = add i32 %A, -124 184; CHECK-NEXT: ret i32 [[C]] 185; 186 %B = sub i32 123, %A 187 %C = xor i32 %B, -1 188 ret i32 %C 189} 190 191define i32 @test18(i32 %A) { 192; CHECK-LABEL: @test18( 193; CHECK-NEXT: [[C:%.*]] = add i32 %A, 124 194; CHECK-NEXT: ret i32 [[C]] 195; 196 %B = xor i32 %A, -1 197 %C = sub i32 123, %B 198 ret i32 %C 199} 200 201define i32 @test19(i32 %A, i32 %B) { 202; CHECK-LABEL: @test19( 203; CHECK-NEXT: ret i32 %B 204; 205 %C = xor i32 %A, %B 206 %D = xor i32 %C, %A 207 ret i32 %D 208} 209 210define void @test20(i32 %A, i32 %B) { 211; CHECK-LABEL: @test20( 212; CHECK-NEXT: store i32 %B, i32* @G1, align 4 213; CHECK-NEXT: store i32 %A, i32* @G2, align 4 214; CHECK-NEXT: ret void 215; 216 %t2 = xor i32 %B, %A 217 %t5 = xor i32 %t2, %B 218 %t8 = xor i32 %t5, %t2 219 store i32 %t8, i32* @G1 220 store i32 %t5, i32* @G2 221 ret void 222} 223 224define i32 @test21(i1 %C, i32 %A, i32 %B) { 225; CHECK-LABEL: @test21( 226; CHECK-NEXT: [[D:%.*]] = select i1 %C, i32 %B, i32 %A 227; CHECK-NEXT: ret i32 [[D]] 228; 229 %C2 = xor i1 %C, true 230 %D = select i1 %C2, i32 %A, i32 %B 231 ret i32 %D 232} 233 234define i32 @test22(i1 %X) { 235; CHECK-LABEL: @test22( 236; CHECK-NEXT: [[TMP1:%.*]] = zext i1 %X to i32 237; CHECK-NEXT: ret i32 [[TMP1]] 238; 239 %Y = xor i1 %X, true 240 %Z = zext i1 %Y to i32 241 %Q = xor i32 %Z, 1 242 ret i32 %Q 243} 244 245; Look through a zext between xors. 246 247define i32 @fold_zext_xor_sandwich(i1 %X) { 248; CHECK-LABEL: @fold_zext_xor_sandwich( 249; CHECK-NEXT: [[TMP1:%.*]] = zext i1 %X to i32 250; CHECK-NEXT: [[Q:%.*]] = xor i32 [[TMP1]], 3 251; CHECK-NEXT: ret i32 [[Q]] 252; 253 %Y = xor i1 %X, true 254 %Z = zext i1 %Y to i32 255 %Q = xor i32 %Z, 2 256 ret i32 %Q 257} 258 259define <2 x i32> @fold_zext_xor_sandwich_vec(<2 x i1> %X) { 260; CHECK-LABEL: @fold_zext_xor_sandwich_vec( 261; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i1> %X to <2 x i32> 262; CHECK-NEXT: [[Q:%.*]] = xor <2 x i32> [[TMP1]], <i32 3, i32 3> 263; CHECK-NEXT: ret <2 x i32> [[Q]] 264; 265 %Y = xor <2 x i1> %X, <i1 true, i1 true> 266 %Z = zext <2 x i1> %Y to <2 x i32> 267 %Q = xor <2 x i32> %Z, <i32 2, i32 2> 268 ret <2 x i32> %Q 269} 270 271define i1 @test23(i32 %a, i32 %b) { 272; CHECK-LABEL: @test23( 273; CHECK-NEXT: [[T4:%.*]] = icmp eq i32 %b, 0 274; CHECK-NEXT: ret i1 [[T4]] 275; 276 %t2 = xor i32 %b, %a 277 %t4 = icmp eq i32 %t2, %a 278 ret i1 %t4 279} 280 281define i1 @test24(i32 %c, i32 %d) { 282; CHECK-LABEL: @test24( 283; CHECK-NEXT: [[T4:%.*]] = icmp ne i32 %d, 0 284; CHECK-NEXT: ret i1 [[T4]] 285; 286 %t2 = xor i32 %d, %c 287 %t4 = icmp ne i32 %t2, %c 288 ret i1 %t4 289} 290 291define i32 @test25(i32 %g, i32 %h) { 292; CHECK-LABEL: @test25( 293; CHECK-NEXT: [[T4:%.*]] = and i32 %h, %g 294; CHECK-NEXT: ret i32 [[T4]] 295; 296 %h2 = xor i32 %h, -1 297 %t2 = and i32 %h2, %g 298 %t4 = xor i32 %t2, %g 299 ret i32 %t4 300} 301 302define i32 @test26(i32 %a, i32 %b) { 303; CHECK-LABEL: @test26( 304; CHECK-NEXT: [[T4:%.*]] = and i32 %a, %b 305; CHECK-NEXT: ret i32 [[T4]] 306; 307 %b2 = xor i32 %b, -1 308 %t2 = xor i32 %a, %b2 309 %t4 = and i32 %t2, %a 310 ret i32 %t4 311} 312 313define i32 @test27(i32 %b, i32 %c, i32 %d) { 314; CHECK-LABEL: @test27( 315; CHECK-NEXT: [[T6:%.*]] = icmp eq i32 %b, %c 316; CHECK-NEXT: [[T7:%.*]] = zext i1 [[T6]] to i32 317; CHECK-NEXT: ret i32 [[T7]] 318; 319 %t2 = xor i32 %d, %b 320 %t5 = xor i32 %d, %c 321 %t6 = icmp eq i32 %t2, %t5 322 %t7 = zext i1 %t6 to i32 323 ret i32 %t7 324} 325 326define i32 @test28(i32 %indvar) { 327; CHECK-LABEL: @test28( 328; CHECK-NEXT: [[T214:%.*]] = add i32 %indvar, 1 329; CHECK-NEXT: ret i32 [[T214]] 330; 331 %t7 = add i32 %indvar, -2147483647 332 %t214 = xor i32 %t7, -2147483648 333 ret i32 %t214 334} 335