Skip to content

Commit bb3f99c

Browse files
committed
[llvm-reduce] Fix crash when reducing integer vectors to 1
Integer vectors were previously ignored when reducing operands. When 6b8bd0f introduced support for reducing floating-point scalars/vectors, the vector case was written to only handle floating-point values. It would crash when creating an invalid ConstantFP from the integer element type. Instead of reinstating the old integer vector behaviour, we might as well reduce integer vectors to all-one splats. A couple of existing tests has also been renamed from "remove" to "reduce" to better reflect the deltas they test. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D129629
1 parent 69b6454 commit bb3f99c

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

llvm/test/tools/llvm-reduce/remove-operands-fp.ll renamed to llvm/test/tools/llvm-reduce/reduce-operands-fp.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
; CHECK-INTERESTINGNESS: = fadd <2 x float>
2626
; CHECK-INTERESTINGNESS: = fadd <2 x float>
2727
; CHECK-INTERESTINGNESS: = fadd <2 x float>
28+
; CHECK-INTERESTINGNESS: = fadd <2 x float>
2829

2930
; CHECK-LABEL: define void @foo(
3031

@@ -41,6 +42,7 @@
4142
; ONE: %fadd9 = fadd <2 x float> <float 1.000000e+00, float 1.000000e+00>, <float 1.000000e+00, float 1.000000e+00>
4243
; ONE: %fadd10 = fadd <2 x float> <float 1.000000e+00, float 1.000000e+00>, <float 1.000000e+00, float 1.000000e+00>
4344
; ONE: %fadd11 = fadd <2 x float> <float 1.000000e+00, float 1.000000e+00>, <float 1.000000e+00, float 1.000000e+00>
45+
; ONE: %fadd12 = fadd <2 x float> <float 1.000000e+00, float 1.000000e+00>, <float 1.000000e+00, float 1.000000e+00>
4446

4547

4648
; ZERO: %fadd0 = fadd float %arg0, 0.000000e+00
@@ -55,6 +57,7 @@
5557
; ZERO: %fadd9 = fadd <2 x float> zeroinitializer, zeroinitializer
5658
; ZERO: %fadd10 = fadd <2 x float> zeroinitializer, zeroinitializer
5759
; ZERO: %fadd11 = fadd <2 x float> zeroinitializer, zeroinitializer
60+
; ZERO: %fadd12 = fadd <2 x float> zeroinitializer, zeroinitializer
5861

5962

6063
; NAN: %fadd0 = fadd float %arg0, 0x7FF8000000000000
@@ -69,6 +72,7 @@
6972
; NAN: %fadd9 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 1.000000e+00, float 1.000000e+00>
7073
; NAN: %fadd10 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
7174
; NAN: %fadd11 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
75+
; NAN: %fadd12 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
7276

7377
define void @foo(float %arg0, float %arg1, <2 x float> %arg2, <2 x float> %arg3) {
7478
bb0:
@@ -84,5 +88,6 @@ bb0:
8488
%fadd9 = fadd <2 x float> %arg2, <float 1.0, float 1.0>
8589
%fadd10 = fadd <2 x float> %arg2, undef
8690
%fadd11 = fadd <2 x float> %arg2, <float 0x7FF8000000000000, float 0x7FF8000000000000>
91+
%fadd12 = fadd <2 x float> %arg2, <float 0x7FF8000000000000, float 2.0>
8792
ret void
8893
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; Test that llvm-reduce can reduce floating point operands
2+
;
3+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-one --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
4+
; RUN: FileCheck --check-prefixes=CHECK,ONE %s < %t
5+
6+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=operands-zero --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
7+
; RUN: FileCheck --check-prefixes=CHECK,ZERO %s < %t
8+
9+
; RUN: llvm-reduce --abort-on-invalid-reduction --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
10+
; RUN: FileCheck --check-prefixes=CHECK,ZERO %s < %t
11+
12+
; CHECK-INTERESTINGNESS: = add i32 %
13+
; CHECK-INTERESTINGNESS: = add i32
14+
; CHECK-INTERESTINGNESS: = add i32
15+
; CHECK-INTERESTINGNESS: = add i32
16+
; CHECK-INTERESTINGNESS: = add i32
17+
18+
; CHECK-INTERESTINGNESS: = add <2 x i32> %
19+
; CHECK-INTERESTINGNESS: = add <2 x i32>
20+
; CHECK-INTERESTINGNESS: = add <2 x i32>
21+
; CHECK-INTERESTINGNESS: = add <2 x i32>
22+
; CHECK-INTERESTINGNESS: = add <2 x i32>
23+
; CHECK-INTERESTINGNESS: = add <2 x i32>
24+
25+
; CHECK-LABEL: define void @foo(
26+
27+
28+
; ONE: %add0 = add i32 %arg0, 1
29+
; ONE: %add1 = add i32 1, 1
30+
; ONE: %add2 = add i32 1, 0
31+
; ONE: %add3 = add i32 1, 1
32+
; ONE: %add4 = add i32 1, 1
33+
; ONE: %add5 = add <2 x i32> %arg2, <i32 1, i32 1>
34+
; ONE: %add6 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
35+
; ONE: %add7 = add <2 x i32> <i32 1, i32 1>, zeroinitializer
36+
; ONE: %add8 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
37+
; ONE: %add9 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
38+
; ONE: %add10 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
39+
40+
41+
; ZERO: %add0 = add i32 %arg0, 0
42+
; ZERO: %add1 = add i32 0, 0
43+
; ZERO: %add2 = add i32 0, 0
44+
; ZERO: %add3 = add i32 0, 0
45+
; ZERO: %add4 = add i32 0, 0
46+
; ZERO: %add5 = add <2 x i32> %arg2, zeroinitializer
47+
; ZERO: %add6 = add <2 x i32> zeroinitializer, zeroinitializer
48+
; ZERO: %add7 = add <2 x i32> zeroinitializer, zeroinitializer
49+
; ZERO: %add8 = add <2 x i32> zeroinitializer, zeroinitializer
50+
; ZERO: %add9 = add <2 x i32> zeroinitializer, zeroinitializer
51+
; ZERO: %add10 = add <2 x i32> zeroinitializer, zeroinitializer
52+
53+
define void @foo(i32 %arg0, i32 %arg1, <2 x i32> %arg2, <2 x i32> %arg3) {
54+
bb0:
55+
%add0 = add i32 %arg0, %arg1
56+
%add1 = add i32 %arg0, %arg1
57+
%add2 = add i32 %arg0, 0
58+
%add3 = add i32 %arg0, 1
59+
%add4 = add i32 %arg0, undef
60+
%add5 = add <2 x i32> %arg2, %arg3
61+
%add6 = add <2 x i32> %arg2, %arg3
62+
%add7 = add <2 x i32> %arg2, zeroinitializer
63+
%add8 = add <2 x i32> %arg2, <i32 1, i32 1>
64+
%add9 = add <2 x i32> %arg2, undef
65+
%add10 = add <2 x i32> %arg2, <i32 4, i32 6>
66+
ret void
67+
}

llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) {
7979
return isZeroOrOneFP(Op) ? nullptr : ConstantFP::get(Ty, 1.0);
8080

8181
if (VectorType *VT = dyn_cast<VectorType>(Ty)) {
82-
if (isZeroOrOneFP(Op))
82+
if (isOne(Op) || isZero(Op) || isZeroOrOneFP(Op))
8383
return nullptr;
8484

85+
if (auto *IntTy = dyn_cast<IntegerType>(VT->getElementType()))
86+
return ConstantVector::getSplat(VT->getElementCount(),
87+
ConstantInt::get(IntTy, 1));
88+
8589
return ConstantVector::getSplat(
8690
VT->getElementCount(), ConstantFP::get(VT->getElementType(), 1.0));
8791
}

0 commit comments

Comments
 (0)