diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2022-06-09 09:43:09 -0400 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2022-06-16 20:13:17 -0400 |
commit | 6b8bd0f72df8dadc7cb23ccaa4ba3bb257e367a5 (patch) | |
tree | 6ade5e56a13eb84fe06b735742964f0a5099e4d9 /llvm/tools/llvm-reduce | |
parent | 2e0c46044a5df9420375d73b25524b47db02a00f (diff) | |
download | llvm-6b8bd0f72df8dadc7cb23ccaa4ba3bb257e367a5.zip llvm-6b8bd0f72df8dadc7cb23ccaa4ba3bb257e367a5.tar.gz llvm-6b8bd0f72df8dadc7cb23ccaa4ba3bb257e367a5.tar.bz2 |
llvm-reduce: Support replacing FP values with 1.0
Diffstat (limited to 'llvm/tools/llvm-reduce')
-rw-r--r-- | llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp index 5bfd876..02b0bd2 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceOperands.cpp @@ -11,9 +11,11 @@ #include "llvm/IR/InstIterator.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" using namespace llvm; +using namespace PatternMatch; static void extractOperandsFromModule(Oracle &O, Module &Program, @@ -39,6 +41,12 @@ static bool isZero(Use &Op) { return C && C->isNullValue(); } +static bool isZeroOrOneFP(Value *Op) { + const APFloat *C; + return match(Op, m_APFloat(C)) && + ((C->isZero() && !C->isNegative()) || C->isExactlyValue(1.0)); +} + static bool shouldReduceOperand(Use &Op) { Type *Ty = Op->getType(); if (Ty->isLabelTy() || Ty->isMetadataTy()) @@ -70,14 +78,27 @@ void llvm::reduceOperandsUndefDeltaPass(TestRunner &Test) { void llvm::reduceOperandsOneDeltaPass(TestRunner &Test) { errs() << "*** Reducing Operands to one...\n"; auto ReduceValue = [](Use &Op) -> Value * { - // TODO: support floats if (!shouldReduceOperand(Op)) return nullptr; - auto *Ty = dyn_cast<IntegerType>(Op->getType()); - if (!Ty) - return nullptr; - // Don't replace existing ones and zeroes. - return (isOne(Op) || isZero(Op)) ? nullptr : ConstantInt::get(Ty, 1); + + Type *Ty = Op->getType(); + if (auto *IntTy = dyn_cast<IntegerType>(Ty)) { + // Don't replace existing ones and zeroes. + return (isOne(Op) || isZero(Op)) ? nullptr : ConstantInt::get(IntTy, 1); + } + + if (Ty->isFloatingPointTy()) + return isZeroOrOneFP(Op) ? nullptr : ConstantFP::get(Ty, 1.0); + + if (VectorType *VT = dyn_cast<VectorType>(Ty)) { + if (isZeroOrOneFP(Op)) + return nullptr; + + return ConstantVector::getSplat( + VT->getElementCount(), ConstantFP::get(VT->getElementType(), 1.0)); + } + + return nullptr; }; runDeltaPass(Test, [ReduceValue](Oracle &O, Module &Program) { extractOperandsFromModule(O, Program, ReduceValue); |