[llvm-dev] InstCombine doesn't delete instructions with token
Alexandre Isoard via llvm-dev
llvm-dev at lists.llvm.org
Tue Jun 16 19:33:07 PDT 2020
Hello David,
I am having an issue with some custom intrinsics that return a token value:
InstCombine deletes the users of the token but not the instruction that
creates the token itself. The IR is still valid but it's wasted.
The source of the issue is coming from an old patch of yours:
commit 7204cff0a121ebc770cf81f7f94679ae7324daae
Author: David Majnemer <david.majnemer at gmail.com>
Date: Fri Nov 6 21:26:32 2015 +0000
[InstCombine] Don't RAUW tokens with undef
Let SimplifyCFG remove unreachable BBs which define token instructions.
llvm-svn: 252343
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3012,7 +3012,7 @@ static bool prepareICWorklistFromFunction(Function
&F, const DataLayout &DL,
while (EndInst != BB->begin()) {
// Delete the next to last instruction.
Instruction *Inst = &*--EndInst->getIterator();
- if (!Inst->use_empty())
+ if (!Inst->use_empty() && !Inst->getType()->isTokenTy())
Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
- if (Inst->isEHPad()) {
+ if (Inst->isEHPad() || Inst->getType()->isTokenTy()) {
EndInst = Inst;
@@ -3022,7 +3022,8 @@ static bool prepareICWorklistFromFunction(Function
&F, const DataLayout &DL,
++NumDeadInst;
MadeIRChange = true;
}
Inst->eraseFromParent();
}
}
I believe the goal was to avoid RAUW the EHPad (as we don't delete the
associated EHRet) and not skip all of the token instructions. At least you
only test on EHPad in the associated unit test.
In which case we could instead do:
while (EndInst != BB->begin()) {
// Delete the next to last instruction.
Instruction *Inst = &*--EndInst->getIterator();
- if (!Inst->use_empty())
+ if (!Inst->use_empty() && !Inst->isEHPad())
Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
if (Inst->isEHPad()) {
EndInst = Inst;
@@ -3022,7 +3022,8 @@ static bool prepareICWorklistFromFunction(Function
&F, const DataLayout &DL,
++NumDeadInst;
MadeIRChange = true;
}
Inst->eraseFromParent();
}
Is my assumption correct?
Note that the code is now in
llvm::removeAllNonTerminatorAndEHPadInstructions of
llvm/lib/Transforms/Utils/Local.cpp
--
*Alexandre Isoard*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200616/56261428/attachment.html>
More information about the llvm-dev
mailing list