[PATCH] D118387: [IPSCCP] Switch away from Instruction::isSafeToRemove()

Kevin P. Neal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 07:16:20 PST 2022


kpn updated this revision to Diff 404924.
kpn added a comment.

No, actually wouldInstructionBeTriviallyDead() rejects some instructions that the previous isSafeToRemove() function allowed. By trusting a true returned by wouldInstructionBeTriviallyDead(), but using the old logic if it returned false, we can make this change NFC. To that end I have also removed the constrained FP logic and I plan on adding it back in probably D115737 <https://reviews.llvm.org/D115737>.


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

https://reviews.llvm.org/D118387

Files:
  llvm/lib/Transforms/Scalar/SCCP.cpp


Index: llvm/lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SCCP.cpp
+++ llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -97,6 +97,13 @@
   return !LV.isUnknownOrUndef() && !isConstant(LV);
 }
 
+static bool canSCCPRemoveInstruction(Instruction *I) {
+  if (wouldInstructionBeTriviallyDead(I))
+    return true;
+
+  return (!isa<CallInst>(I) || !I->mayHaveSideEffects()) && !I->isTerminator();
+}
+
 static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
   Constant *Const = nullptr;
   if (V->getType()->isStructTy()) {
@@ -127,7 +134,8 @@
   // Calls with "clang.arc.attachedcall" implicitly use the return value and
   // those uses cannot be updated with a constant.
   CallBase *CB = dyn_cast<CallBase>(V);
-  if (CB && ((CB->isMustTailCall() && !CB->isSafeToRemove()) ||
+  if (CB && ((CB->isMustTailCall() &&
+              !canSCCPRemoveInstruction(CB)) ||
              CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall))) {
     Function *F = CB->getCalledFunction();
 
@@ -156,7 +164,7 @@
     if (Inst.getType()->isVoidTy())
       continue;
     if (tryToReplaceWithConstant(Solver, &Inst)) {
-      if (Inst.isSafeToRemove())
+      if (canSCCPRemoveInstruction(&Inst))
         Inst.eraseFromParent();
 
       MadeChanges = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118387.404924.patch
Type: text/x-patch
Size: 1345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220201/019063bd/attachment.bin>


More information about the llvm-commits mailing list