[PATCH] D127440: llvm-reduce: Handle reducing FP values to nan
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 13:57:14 PDT 2022
arsenm created this revision.
arsenm added reviewers: aeubanks, swamulism, lebedev.ri, fhahn, dblaikie, diegotf.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
I'm not sure what the precedence of this should be compared to
replacing with zero/one/undef. Currently this will win out over the
others if it doesn't matter to the reduction. This has similar
advantages to undef.
https://reviews.llvm.org/D127440
Files:
llvm/test/tools/llvm-reduce/remove-operands-fp.ll
llvm/tools/llvm-reduce/DeltaManager.cpp
llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
llvm/tools/llvm-reduce/deltas/ReduceOperands.h
Index: llvm/tools/llvm-reduce/deltas/ReduceOperands.h
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceOperands.h
+++ llvm/tools/llvm-reduce/deltas/ReduceOperands.h
@@ -15,6 +15,7 @@
void reduceOperandsUndefDeltaPass(TestRunner &Test);
void reduceOperandsOneDeltaPass(TestRunner &Test);
void reduceOperandsZeroDeltaPass(TestRunner &Test);
+void reduceOperandsNaNDeltaPass(TestRunner &Test);
} // namespace llvm
#endif
Index: llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp
@@ -117,3 +117,25 @@
extractOperandsFromModule(O, Program, ReduceValue);
});
}
+
+void llvm::reduceOperandsNaNDeltaPass(TestRunner &Test) {
+ errs() << "*** Reducing Operands to NaN...\n";
+ auto ReduceValue = [](Use &Op) -> Value * {
+ Type *Ty = Op->getType();
+ if (!Ty->isFPOrFPVectorTy())
+ return nullptr;
+
+ if (match(Op.get(), m_NaN()))
+ return nullptr;
+
+ if (VectorType *VT = dyn_cast<VectorType>(Ty)) {
+ return ConstantVector::getSplat(VT->getElementCount(),
+ ConstantFP::getQNaN(VT->getElementType()));
+ }
+
+ return ConstantFP::getQNaN(Ty);
+ };
+ runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) {
+ extractOperandsFromModule(O, Program, ReduceValue);
+ });
+}
Index: llvm/tools/llvm-reduce/DeltaManager.cpp
===================================================================
--- llvm/tools/llvm-reduce/DeltaManager.cpp
+++ llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -68,6 +68,7 @@
DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass) \
DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) \
DELTA_PASS("operands-undef", reduceOperandsUndefDeltaPass) \
+ DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) \
DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass) \
DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass) \
DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass) \
Index: llvm/test/tools/llvm-reduce/remove-operands-fp.ll
===================================================================
--- llvm/test/tools/llvm-reduce/remove-operands-fp.ll
+++ llvm/test/tools/llvm-reduce/remove-operands-fp.ll
@@ -9,8 +9,11 @@
; 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 --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 --delta-passes=operands-nan --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefixes=CHECK,NAN %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,NAN %s < %t
; CHECK-INTERESTINGNESS: = fadd float %
; CHECK-INTERESTINGNESS: = fadd float
@@ -69,6 +72,20 @@
; ZERO: %fadd10 = fadd <2 x float> zeroinitializer, zeroinitializer
; ZERO: %fadd11 = fadd <2 x float> zeroinitializer, zeroinitializer
+
+; NAN: %fadd0 = fadd float %arg0, 0x7FF8000000000000
+; NAN: %fadd1 = fadd float 0x7FF8000000000000, 0x7FF8000000000000
+; NAN: %fadd2 = fadd float 0x7FF8000000000000, 0x7FF8000000000000
+; NAN: %fadd3 = fadd float 0x7FF8000000000000, 0x7FF8000000000000
+; NAN: %fadd4 = fadd float 0x7FF8000000000000, 0x7FF8000000000000
+; NAN: %fadd5 = fadd float 0x7FF8000000000000, 0x7FF8000000000000
+; NAN: %fadd6 = fadd <2 x float> %arg2, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+; NAN: %fadd7 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+; NAN: %fadd8 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+; NAN: %fadd9 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+; NAN: %fadd10 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+; NAN: %fadd11 = fadd <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <float 0x7FF8000000000000, float 0x7FF8000000000000>
+
define void @foo(float %arg0, float %arg1, <2 x float> %arg2, <2 x float> %arg3) {
bb0:
%fadd0 = fadd float %arg0, %arg1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127440.435672.patch
Type: text/x-patch
Size: 4998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220609/0a0d6003/attachment.bin>
More information about the llvm-commits
mailing list