[llvm] [InstCombine] If return-inst in unreachable refers to an inst change it to poison (#65107) (PR #78444)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 20:46:29 PST 2024


================
@@ -2779,6 +2779,11 @@ llvm::removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB) {
   Instruction *EndInst = BB->getTerminator(); // Last not to be deleted.
   // RemoveDIs: erasing debug-info must be done manually.
   EndInst->dropDbgValues();
+
+  if (isa<ReturnInst>(EndInst) && EndInst->getNumOperands() > 0 &&
+      isa<Instruction>(EndInst->getOperand(0)))
+    EndInst->setOperand(0, PoisonValue::get(EndInst->getOperand(0)->getType()));
----------------
ParkHanbum wrote:

@nikic got it. 
//‘ret’, ‘br’, 
// ‘switch’, ‘indirectbr’, ‘invoke’, ‘callbr’ ‘resume’, 
//‘catchswitch’, ‘catchret’, ‘cleanupret’, and ‘unreachable’.

I'll implement codes to handle above terminators.
except `CatchSwitch`. it is element of EHPad can be skipped.


https://github.com/llvm/llvm-project/pull/78444


More information about the llvm-commits mailing list