OSDN Git Service

[InstCombine] add FMF guard to builder in fptrunc transform; NFC
authorSanjay Patel <spatel@rotateright.com>
Thu, 5 Dec 2019 15:50:43 +0000 (10:50 -0500)
committerSanjay Patel <spatel@rotateright.com>
Thu, 5 Dec 2019 15:55:07 +0000 (10:55 -0500)
This makes no difference currently because we don't apply FMF
to FP casts, but that may change.

This could also be a place to add a fold for select with fptrunc,
so it will make that patch easier/smaller.

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

index 2171c81..53bcaeb 100644 (file)
@@ -1622,6 +1622,11 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
   Value *X;
   Instruction *Op = dyn_cast<Instruction>(FPT.getOperand(0));
   if (Op && Op->hasOneUse()) {
+    // FIXME: The FMF should propagate from the fptrunc, not the source op.
+    IRBuilder<>::FastMathFlagGuard FMFG(Builder);
+    if (isa<FPMathOperator>(Op))
+      Builder.setFastMathFlags(Op->getFastMathFlags());
+
     if (match(Op, m_FNeg(m_Value(X)))) {
       Value *InnerTrunc = Builder.CreateFPTrunc(X, Ty);