1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @reduce_add_self(<8 x i1> %x) {
5 ; CHECK-LABEL: @reduce_add_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: [[RES:%.*]] = icmp ne i8 [[TMP3]], 0
10 ; CHECK-NEXT: ret i1 [[RES]]
12 %res = call i1 @llvm.vector.reduce.add.v8i32(<8 x i1> %x)
16 define i32 @reduce_add_sext(<4 x i1> %x) {
17 ; CHECK-LABEL: @reduce_add_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:%.*]] = zext nneg i4 [[TMP2]] to i32
21 ; CHECK-NEXT: [[RES:%.*]] = sub nsw i32 0, [[TMP3]]
22 ; CHECK-NEXT: ret i32 [[RES]]
24 %sext = sext <4 x i1> %x to <4 x i32>
25 %res = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %sext)
29 define i64 @reduce_add_zext(<8 x i1> %x) {
30 ; CHECK-LABEL: @reduce_add_zext(
31 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
32 ; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ctpop.i8(i8 [[TMP1]]), !range [[RNG0]]
33 ; CHECK-NEXT: [[RES:%.*]] = zext nneg i8 [[TMP2]] to i64
34 ; CHECK-NEXT: ret i64 [[RES]]
36 %zext = zext <8 x i1> %x to <8 x i64>
37 %res = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %zext)
41 define i16 @reduce_add_sext_same(<16 x i1> %x) {
42 ; CHECK-LABEL: @reduce_add_sext_same(
43 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i1> [[X:%.*]] to i16
44 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.ctpop.i16(i16 [[TMP1]]), !range [[RNG2:![0-9]+]]
45 ; CHECK-NEXT: [[RES:%.*]] = sub nsw i16 0, [[TMP2]]
46 ; CHECK-NEXT: ret i16 [[RES]]
48 %sext = sext <16 x i1> %x to <16 x i16>
49 %res = call i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %sext)
53 define i8 @reduce_add_zext_long(<128 x i1> %x) {
54 ; CHECK-LABEL: @reduce_add_zext_long(
55 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
56 ; CHECK-NEXT: [[TMP2:%.*]] = call i128 @llvm.ctpop.i128(i128 [[TMP1]]), !range [[RNG3:![0-9]+]]
57 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i8
58 ; CHECK-NEXT: [[RES:%.*]] = sub i8 0, [[TMP3]]
59 ; CHECK-NEXT: ret i8 [[RES]]
61 %sext = sext <128 x i1> %x to <128 x i8>
62 %res = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %sext)
66 @glob = external global i8, align 1
67 define i8 @reduce_add_zext_long_external_use(<128 x i1> %x) {
68 ; CHECK-LABEL: @reduce_add_zext_long_external_use(
69 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
70 ; CHECK-NEXT: [[TMP2:%.*]] = call i128 @llvm.ctpop.i128(i128 [[TMP1]]), !range [[RNG3]]
71 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i128 [[TMP2]] to i8
72 ; CHECK-NEXT: [[RES:%.*]] = sub i8 0, [[TMP3]]
73 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <128 x i1> [[X]], i64 0
74 ; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[TMP4]] to i8
75 ; CHECK-NEXT: store i8 [[EXT]], ptr @glob, align 1
76 ; CHECK-NEXT: ret i8 [[RES]]
78 %sext = sext <128 x i1> %x to <128 x i8>
79 %res = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %sext)
80 %ext = extractelement <128 x i8> %sext, i32 0
81 store i8 %ext, ptr @glob, align 1
85 @glob1 = external global i64, align 8
86 define i64 @reduce_add_zext_external_use(<8 x i1> %x) {
87 ; CHECK-LABEL: @reduce_add_zext_external_use(
88 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
89 ; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ctpop.i8(i8 [[TMP1]]), !range [[RNG0]]
90 ; CHECK-NEXT: [[RES:%.*]] = zext nneg i8 [[TMP2]] to i64
91 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <8 x i1> [[X]], i64 0
92 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[TMP3]] to i64
93 ; CHECK-NEXT: store i64 [[EXT]], ptr @glob1, align 8
94 ; CHECK-NEXT: ret i64 [[RES]]
96 %zext = zext <8 x i1> %x to <8 x i64>
97 %res = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %zext)
98 %ext = extractelement <8 x i64> %zext, i32 0
99 store i64 %ext, ptr @glob1, align 8
103 declare i1 @llvm.vector.reduce.add.v8i32(<8 x i1> %a)
104 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
105 declare i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %a)
106 declare i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %a)
107 declare i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %a)