1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i1 @reduce_xor_self(<8 x i1> %x) {
5 ; CHECK-LABEL: @reduce_xor_self(
6 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
7 ; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ctpop.i8(i8 [[TMP1]]), !range [[RNG0:![0-9]+]]
8 ; CHECK-NEXT: [[TMP3:%.*]] = and i8 [[TMP2]], 1
9 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i8 [[TMP3]], 0
10 ; CHECK-NEXT: ret i1 [[TMP4]]
12 %res = call i1 @llvm.vector.reduce.xor.v8i32(<8 x i1> %x)
16 define i32 @reduce_xor_sext(<4 x i1> %x) {
17 ; CHECK-LABEL: @reduce_xor_sext(
18 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i1> [[X:%.*]] to i4
19 ; CHECK-NEXT: [[TMP2:%.*]] = call i4 @llvm.ctpop.i4(i4 [[TMP1]]), !range [[RNG1:![0-9]+]]
20 ; CHECK-NEXT: [[TMP3:%.*]] = and i4 [[TMP2]], 1
21 ; CHECK-NEXT: [[SEXT:%.*]] = sub nsw i4 0, [[TMP3]]
22 ; CHECK-NEXT: [[TMP4:%.*]] = sext i4 [[SEXT]] to i32
23 ; CHECK-NEXT: ret i32 [[TMP4]]
25 %sext = sext <4 x i1> %x to <4 x i32>
26 %res = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %sext)
30 define i64 @reduce_xor_zext(<8 x i1> %x) {
31 ; CHECK-LABEL: @reduce_xor_zext(
32 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
33 ; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ctpop.i8(i8 [[TMP1]]), !range [[RNG0]]
34 ; CHECK-NEXT: [[TMP3:%.*]] = and i8 [[TMP2]], 1
35 ; CHECK-NEXT: [[TMP4:%.*]] = zext i8 [[TMP3]] to i64
36 ; CHECK-NEXT: ret i64 [[TMP4]]
38 %zext = zext <8 x i1> %x to <8 x i64>
39 %res = call i64 @llvm.vector.reduce.xor.v8i64(<8 x i64> %zext)
43 define i16 @reduce_xor_sext_same(<16 x i1> %x) {
44 ; CHECK-LABEL: @reduce_xor_sext_same(
45 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i1> [[X:%.*]] to i16
46 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.ctpop.i16(i16 [[TMP1]]), !range [[RNG2:![0-9]+]]
47 ; CHECK-NEXT: [[TMP3:%.*]] = and i16 [[TMP2]], 1
48 ; CHECK-NEXT: [[SEXT:%.*]] = sub nsw i16 0, [[TMP3]]
49 ; CHECK-NEXT: ret i16 [[SEXT]]
51 %sext = sext <16 x i1> %x to <16 x i16>
52 %res = call i16 @llvm.vector.reduce.xor.v16i16(<16 x i16> %sext)
56 define i8 @reduce_xor_zext_long(<128 x i1> %x) {
57 ; CHECK-LABEL: @reduce_xor_zext_long(
58 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
59 ; CHECK-NEXT: [[TMP2:%.*]] = call i128 @llvm.ctpop.i128(i128 [[TMP1]]), !range [[RNG3:![0-9]+]]
60 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i8
61 ; CHECK-NEXT: [[TMP4:%.*]] = and i8 [[TMP3]], 1
62 ; CHECK-NEXT: [[TMP5:%.*]] = sub nsw i8 0, [[TMP4]]
63 ; CHECK-NEXT: ret i8 [[TMP5]]
65 %sext = sext <128 x i1> %x to <128 x i8>
66 %res = call i8 @llvm.vector.reduce.xor.v128i8(<128 x i8> %sext)
70 @glob = external global i8, align 1
71 define i8 @reduce_xor_zext_long_external_use(<128 x i1> %x) {
72 ; CHECK-LABEL: @reduce_xor_zext_long_external_use(
73 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
74 ; CHECK-NEXT: [[TMP2:%.*]] = call i128 @llvm.ctpop.i128(i128 [[TMP1]]), !range [[RNG3]]
75 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i8
76 ; CHECK-NEXT: [[TMP4:%.*]] = and i8 [[TMP3]], 1
77 ; CHECK-NEXT: [[TMP5:%.*]] = sub nsw i8 0, [[TMP4]]
78 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <128 x i1> [[X]], i32 0
79 ; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[TMP6]] to i8
80 ; CHECK-NEXT: store i8 [[EXT]], i8* @glob, align 1
81 ; CHECK-NEXT: ret i8 [[TMP5]]
83 %sext = sext <128 x i1> %x to <128 x i8>
84 %res = call i8 @llvm.vector.reduce.xor.v128i8(<128 x i8> %sext)
85 %ext = extractelement <128 x i8> %sext, i32 0
86 store i8 %ext, i8* @glob, align 1
90 @glob1 = external global i64, align 8
91 define i64 @reduce_xor_zext_external_use(<8 x i1> %x) {
92 ; CHECK-LABEL: @reduce_xor_zext_external_use(
93 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
94 ; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ctpop.i8(i8 [[TMP1]]), !range [[RNG0]]
95 ; CHECK-NEXT: [[TMP3:%.*]] = and i8 [[TMP2]], 1
96 ; CHECK-NEXT: [[TMP4:%.*]] = zext i8 [[TMP3]] to i64
97 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x i1> [[X]], i32 0
98 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[TMP5]] to i64
99 ; CHECK-NEXT: store i64 [[EXT]], i64* @glob1, align 8
100 ; CHECK-NEXT: ret i64 [[TMP4]]
102 %zext = zext <8 x i1> %x to <8 x i64>
103 %res = call i64 @llvm.vector.reduce.xor.v8i64(<8 x i64> %zext)
104 %ext = extractelement <8 x i64> %zext, i32 0
105 store i64 %ext, i64* @glob1, align 8
109 declare i1 @llvm.vector.reduce.xor.v8i32(<8 x i1> %a)
110 declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %a)
111 declare i64 @llvm.vector.reduce.xor.v8i64(<8 x i64> %a)
112 declare i16 @llvm.vector.reduce.xor.v16i16(<16 x i16> %a)
113 declare i8 @llvm.vector.reduce.xor.v128i8(<128 x i8> %a)