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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 07:48:22 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()));
----------------
nikic wrote:

We shouldn't hardcode this to `ReturnInst`. We should replace any operand in the terminator. E.g. if this is a `br`, we should also set the condition to poison. (Skip the replacement for token types though.)

You should also do a similar change in `InstCombinerImpl::handleUnreachableFrom`.

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


More information about the llvm-commits mailing list