1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test for (x & y) + ~(x | y) -> ~(x ^ y)
3 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
6 define i32 @src(i32 noundef %0, i32 noundef %1) {
8 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP1:%.*]], [[TMP0:%.*]]
9 ; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP3]], -1
10 ; CHECK-NEXT: ret i32 [[TMP4]]
19 ; vector version of src
20 define <2 x i32> @src_vec(<2 x i32> noundef %0, <2 x i32> noundef %1) {
21 ; CHECK-LABEL: @src_vec(
22 ; CHECK-NEXT: [[TMP3:%.*]] = xor <2 x i32> [[TMP1:%.*]], [[TMP0:%.*]]
23 ; CHECK-NEXT: [[TMP4:%.*]] = xor <2 x i32> [[TMP3]], splat (i32 -1)
24 ; CHECK-NEXT: ret <2 x i32> [[TMP4]]
26 %3 = and <2 x i32> %1, %0
27 %4 = or <2 x i32> %1, %0
28 %5 = xor <2 x i32> %4, <i32 -1, i32 -1>
29 %6 = add <2 x i32> %3, %5
33 ; vector version of src with poison values
34 define <2 x i32> @src_vec_poison(<2 x i32> noundef %0, <2 x i32> noundef %1) {
35 ; CHECK-LABEL: @src_vec_poison(
36 ; CHECK-NEXT: [[TMP3:%.*]] = xor <2 x i32> [[TMP1:%.*]], [[TMP0:%.*]]
37 ; CHECK-NEXT: [[TMP4:%.*]] = xor <2 x i32> [[TMP3]], splat (i32 -1)
38 ; CHECK-NEXT: ret <2 x i32> [[TMP4]]
40 %3 = and <2 x i32> %1, %0
41 %4 = or <2 x i32> %1, %0
42 %5 = xor <2 x i32> %4, <i32 -1, i32 poison>
43 %6 = add <2 x i32> %3, %5
48 define i32 @src2(i32 noundef %0, i32 noundef %1) {
50 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP1:%.*]], [[TMP0:%.*]]
51 ; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP3]], -1
52 ; CHECK-NEXT: ret i32 [[TMP4]]
62 define i32 @src3(i32 noundef %0, i32 noundef %1) {
64 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP1:%.*]], [[TMP0:%.*]]
65 ; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP3]], -1
66 ; CHECK-NEXT: ret i32 [[TMP4]]
77 define i32 @src4(i32 noundef %0, i32 noundef %1) {
79 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP0:%.*]], [[TMP1:%.*]]
80 ; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP3]], -1
81 ; CHECK-NEXT: ret i32 [[TMP4]]
91 define i32 @src5(i32 noundef %0, i32 noundef %1) {
93 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP1:%.*]], [[TMP0:%.*]]
94 ; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP3]], -1
95 ; CHECK-NEXT: ret i32 [[TMP4]]
105 define i32 @src6(i32 %0, i32 %1, i32 %2, i32 %3) {
106 ; CHECK-LABEL: @src6(
107 ; CHECK-NEXT: [[TMP5:%.*]] = and i32 [[TMP0:%.*]], [[TMP1:%.*]]
108 ; CHECK-NEXT: [[TMP6:%.*]] = or i32 [[TMP2:%.*]], [[TMP3:%.*]]
109 ; CHECK-NEXT: [[TMP7:%.*]] = xor i32 [[TMP6]], -1
110 ; CHECK-NEXT: [[TMP8:%.*]] = add i32 [[TMP5]], [[TMP7]]
111 ; CHECK-NEXT: ret i32 [[TMP8]]