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 range(i8 0, 9) i8 @llvm.ctpop.i8(i8 [[TMP1]])
8 ; CHECK-NEXT: [[RES:%.*]] = trunc i8 [[TMP2]] to i1
9 ; CHECK-NEXT: ret i1 [[RES]]
11 %res = call i1 @llvm.vector.reduce.add.v8i32(<8 x i1> %x)
15 define i32 @reduce_add_sext(<4 x i1> %x) {
16 ; CHECK-LABEL: @reduce_add_sext(
17 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i1> [[X:%.*]] to i4
18 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i4 0, 5) i4 @llvm.ctpop.i4(i4 [[TMP1]])
19 ; CHECK-NEXT: [[TMP3:%.*]] = zext nneg i4 [[TMP2]] to i32
20 ; CHECK-NEXT: [[RES:%.*]] = sub nsw i32 0, [[TMP3]]
21 ; CHECK-NEXT: ret i32 [[RES]]
23 %sext = sext <4 x i1> %x to <4 x i32>
24 %res = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %sext)
28 define i64 @reduce_add_zext(<8 x i1> %x) {
29 ; CHECK-LABEL: @reduce_add_zext(
30 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
31 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 [[TMP1]])
32 ; CHECK-NEXT: [[RES:%.*]] = zext nneg i8 [[TMP2]] to i64
33 ; CHECK-NEXT: ret i64 [[RES]]
35 %zext = zext <8 x i1> %x to <8 x i64>
36 %res = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %zext)
40 define i16 @reduce_add_sext_same(<16 x i1> %x) {
41 ; CHECK-LABEL: @reduce_add_sext_same(
42 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <16 x i1> [[X:%.*]] to i16
43 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i16 0, 17) i16 @llvm.ctpop.i16(i16 [[TMP1]])
44 ; CHECK-NEXT: [[RES:%.*]] = sub nsw i16 0, [[TMP2]]
45 ; CHECK-NEXT: ret i16 [[RES]]
47 %sext = sext <16 x i1> %x to <16 x i16>
48 %res = call i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %sext)
52 define i8 @reduce_add_zext_long(<128 x i1> %x) {
53 ; CHECK-LABEL: @reduce_add_zext_long(
54 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
55 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i128 0, 129) i128 @llvm.ctpop.i128(i128 [[TMP1]])
56 ; CHECK-NEXT: [[TMP3:%.*]] = trunc nuw i128 [[TMP2]] to i8
57 ; CHECK-NEXT: [[RES:%.*]] = sub i8 0, [[TMP3]]
58 ; CHECK-NEXT: ret i8 [[RES]]
60 %sext = sext <128 x i1> %x to <128 x i8>
61 %res = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %sext)
65 @glob = external global i8, align 1
66 define i8 @reduce_add_zext_long_external_use(<128 x i1> %x) {
67 ; CHECK-LABEL: @reduce_add_zext_long_external_use(
68 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <128 x i1> [[X:%.*]] to i128
69 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i128 0, 129) i128 @llvm.ctpop.i128(i128 [[TMP1]])
70 ; CHECK-NEXT: [[TMP3:%.*]] = trunc nuw i128 [[TMP2]] to i8
71 ; CHECK-NEXT: [[RES:%.*]] = sub i8 0, [[TMP3]]
72 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <128 x i1> [[X]], i64 0
73 ; CHECK-NEXT: [[EXT:%.*]] = sext i1 [[TMP4]] to i8
74 ; CHECK-NEXT: store i8 [[EXT]], ptr @glob, align 1
75 ; CHECK-NEXT: ret i8 [[RES]]
77 %sext = sext <128 x i1> %x to <128 x i8>
78 %res = call i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %sext)
79 %ext = extractelement <128 x i8> %sext, i32 0
80 store i8 %ext, ptr @glob, align 1
84 @glob1 = external global i64, align 8
85 define i64 @reduce_add_zext_external_use(<8 x i1> %x) {
86 ; CHECK-LABEL: @reduce_add_zext_external_use(
87 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <8 x i1> [[X:%.*]] to i8
88 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 [[TMP1]])
89 ; CHECK-NEXT: [[RES:%.*]] = zext nneg i8 [[TMP2]] to i64
90 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <8 x i1> [[X]], i64 0
91 ; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[TMP3]] to i64
92 ; CHECK-NEXT: store i64 [[EXT]], ptr @glob1, align 8
93 ; CHECK-NEXT: ret i64 [[RES]]
95 %zext = zext <8 x i1> %x to <8 x i64>
96 %res = call i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %zext)
97 %ext = extractelement <8 x i64> %zext, i32 0
98 store i64 %ext, ptr @glob1, align 8
102 declare i1 @llvm.vector.reduce.add.v8i32(<8 x i1> %a)
103 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
104 declare i64 @llvm.vector.reduce.add.v8i64(<8 x i64> %a)
105 declare i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %a)
106 declare i8 @llvm.vector.reduce.add.v128i8(<128 x i8> %a)