[llvm] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 11 15:23:52 PDT 2023
================
@@ -109,6 +110,53 @@ static bool maybeRewriteToFallthrough(MachineInstr &MI, MachineBasicBlock &MBB,
return true;
}
+static bool eraseDeadCodeAroundUnreachable(MachineInstr &UnreachbleMI, MachineBasicBlock &MBB) {
+ SmallVector<MachineInstr*, 16> ToDelete;
+
+ // Because wasm unreachable is stack polymorphic and unconditionally ends control,
+ // all instructions after it can be removed until the end of this block.
+ // We remove the common case of double unreachable.
+ auto ForwardsIterator = UnreachbleMI.getIterator();
+ for (ForwardsIterator++; !ForwardsIterator.isEnd(); ForwardsIterator++) {
+ MachineInstr& MI = *ForwardsIterator;
+ if (MI.getOpcode() == WebAssembly::UNREACHABLE) {
+ ToDelete.push_back(&MI);
+ } else {
+ break;
+ }
+ }
+
+ [&]() {
----------------
sbc100 wrote:
Oh neat trick. Maybe a bit too clever, or a pattern that I'm just not used to seeing in the wild. `goto` sounds better to me but if folks disagree then at least a comment would be good.
https://github.com/llvm/llvm-project/pull/65876
More information about the llvm-commits
mailing list