[clang] [llvm] [IR] Allow fast math flags on fptrunc and fpext (PR #115894)
John Brawn via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 06:24:02 PST 2024
================
@@ -1875,13 +1873,17 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
// fptrunc (select Cond, (fpext X), Y --> select Cond, X, (fptrunc Y)
Value *NarrowY = Builder.CreateFPTrunc(Y, Ty);
Value *Sel = Builder.CreateSelect(Cond, X, NarrowY, "narrow.sel", Op);
+ if (auto *I = dyn_cast<Instruction>(Sel))
+ I->setFastMathFlags(Op->getFastMathFlags());
return replaceInstUsesWith(FPT, Sel);
}
if (match(Op, m_Select(m_Value(Cond), m_Value(Y), m_FPExt(m_Value(X)))) &&
X->getType() == Ty) {
// fptrunc (select Cond, Y, (fpext X) --> select Cond, (fptrunc Y), X
Value *NarrowY = Builder.CreateFPTrunc(Y, Ty);
Value *Sel = Builder.CreateSelect(Cond, NarrowY, X, "narrow.sel", Op);
+ if (auto *I = dyn_cast<Instruction>(Sel))
+ I->setFastMathFlags(Op->getFastMathFlags());
----------------
john-brawn-arm wrote:
I don't think this is possible. Applying this patch first then later applying a patch to instcombine would cause test failures, as I mention in my comment above. Applying a patch to instcombine first doesn't work, because Instruction::getFastMathFlags fails an assert when the instruction isn't an FPMathOperator, which fptrunc wouldn't be at that point.
https://github.com/llvm/llvm-project/pull/115894
More information about the cfe-commits
mailing list