[PATCH] D129191: [IndVars] Eliminate redundant type cast between integer and float

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 02:16:33 PDT 2022


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:681
+  if (!SE->isSCEVable(IVOperand->getType()))
+    return false;
+
----------------
This is probably not needed, as SIToFP operand must be an integer, which is always SCEVable.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:683
+
+  if (UseInst->getOpcode() != CastInst::SIToFP || !UseInst->hasOneUse())
+    return false;
----------------
Why do we care about hasOneUse here? This seems at odds with your users() loop below.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:687
+  // Get the symbolic expression for this instruction.
+  ConstantRange IVRange = SE->getUnsignedRange(SE->getSCEV(IVOperand));
+  unsigned DestNumSigBits = UseInst->getType()->getFPMantissaWidth();
----------------
getSignedRange?


================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:698
+      CI->replaceUsesWithIf(IVOperand, [&](Use &U) -> bool {
+        return DT->dominates(IVOperand, U);
+      });
----------------
How can IVOperand not dominate U? IVOperands dominates UseInst, which dominates all its uses.


================
Comment at: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp:699
+        return DT->dominates(IVOperand, U);
+      });
+
----------------
There may be a type mismatch here: Either we need to limit to the same type, or insert sext/trunc as necessary.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129191/new/

https://reviews.llvm.org/D129191



More information about the llvm-commits mailing list