[PATCH] D129629: [llvm-reduce] Fix crash when reducing integer vectors to 1
Fraser Cormack via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 03:28:02 PDT 2022
frasercrmck created this revision.
frasercrmck added reviewers: arsenm, fhahn, regehr, aeubanks.
Herald added a project: All.
frasercrmck requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Integer vectors were previously ignored when reducing operands. When
6b8bd0f72 <https://reviews.llvm.org/rG6b8bd0f72df8dadc7cb23ccaa4ba3bb257e367a5> 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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129629
Files:
llvm/test/tools/llvm-reduce/remove-operands-int.ll
llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
@@ -79,9 +79,13 @@
return isZeroOrOneFP(Op) ? nullptr : ConstantFP::get(Ty, 1.0);
if (VectorType *VT = dyn_cast<VectorType>(Ty)) {
- if (isZeroOrOneFP(Op))
+ if (isOne(Op) || isZero(Op) || isZeroOrOneFP(Op))
return nullptr;
+ if (auto *IntTy = dyn_cast<IntegerType>(VT->getElementType()))
+ return ConstantVector::getSplat(VT->getElementCount(),
+ ConstantInt::get(IntTy, 1));
+
return ConstantVector::getSplat(
VT->getElementCount(), ConstantFP::get(VT->getElementType(), 1.0));
}
Index: llvm/test/tools/llvm-reduce/remove-operands-int.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/remove-operands-int.ll
@@ -0,0 +1,63 @@
+; Test that llvm-reduce can reduce floating point operands
+;
+; 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
+; RUN: FileCheck --check-prefixes=CHECK,ONE %s < %t
+
+; 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
+; RUN: FileCheck --check-prefixes=CHECK,ZERO %s < %t
+
+; 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
+; RUN: FileCheck --check-prefixes=CHECK,ZERO %s < %t
+
+; CHECK-INTERESTINGNESS: = add i32 %
+; CHECK-INTERESTINGNESS: = add i32
+; CHECK-INTERESTINGNESS: = add i32
+; CHECK-INTERESTINGNESS: = add i32
+; CHECK-INTERESTINGNESS: = add i32
+
+; CHECK-INTERESTINGNESS: = add <2 x i32> %
+; CHECK-INTERESTINGNESS: = add <2 x i32>
+; CHECK-INTERESTINGNESS: = add <2 x i32>
+; CHECK-INTERESTINGNESS: = add <2 x i32>
+; CHECK-INTERESTINGNESS: = add <2 x i32>
+
+; CHECK-LABEL: define void @foo(
+
+
+; ONE: %add0 = add i32 %arg0, 1
+; ONE: %add1 = add i32 1, 1
+; ONE: %add2 = add i32 1, 0
+; ONE: %add3 = add i32 1, 1
+; ONE: %add4 = add i32 1, 1
+; ONE: %add5 = add <2 x i32> %arg2, <i32 1, i32 1>
+; ONE: %add6 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
+; ONE: %add7 = add <2 x i32> <i32 1, i32 1>, zeroinitializer
+; ONE: %add8 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
+; ONE: %add9 = add <2 x i32> <i32 1, i32 1>, <i32 1, i32 1>
+
+
+; ZERO: %add0 = add i32 %arg0, 0
+; ZERO: %add1 = add i32 0, 0
+; ZERO: %add2 = add i32 0, 0
+; ZERO: %add3 = add i32 0, 0
+; ZERO: %add4 = add i32 0, 0
+; ZERO: %add5 = add <2 x i32> %arg2, zeroinitializer
+; ZERO: %add6 = add <2 x i32> zeroinitializer, zeroinitializer
+; ZERO: %add7 = add <2 x i32> zeroinitializer, zeroinitializer
+; ZERO: %add8 = add <2 x i32> zeroinitializer, zeroinitializer
+; ZERO: %add9 = add <2 x i32> zeroinitializer, zeroinitializer
+
+define void @foo(i32 %arg0, i32 %arg1, <2 x i32> %arg2, <2 x i32> %arg3) {
+bb0:
+ %add0 = add i32 %arg0, %arg1
+ %add1 = add i32 %arg0, %arg1
+ %add2 = add i32 %arg0, 0
+ %add3 = add i32 %arg0, 1
+ %add4 = add i32 %arg0, undef
+ %add5 = add <2 x i32> %arg2, %arg3
+ %add6 = add <2 x i32> %arg2, %arg3
+ %add7 = add <2 x i32> %arg2, zeroinitializer
+ %add8 = add <2 x i32> %arg2, <i32 1, i32 1>
+ %add9 = add <2 x i32> %arg2, undef
+ ret void
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129629.444204.patch
Type: text/x-patch
Size: 3619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220713/c6735240/attachment.bin>
More information about the llvm-commits
mailing list