Index: llvm/lib/IR/Instruction.cpp =================================================================== --- llvm/lib/IR/Instruction.cpp +++ llvm/lib/IR/Instruction.cpp @@ -733,11 +733,7 @@ return !SI->isVolatile(); if (const auto *CB = dyn_cast(this)) - // FIXME: Temporarily assume that all side-effect free intrinsics will - // return. Remove this workaround once all intrinsics are appropriately - // annotated. - return CB->hasFnAttr(Attribute::WillReturn) || - (isa(CB) && CB->onlyReadsMemory()); + return CB->hasFnAttr(Attribute::WillReturn); return true; } Index: llvm/lib/Transforms/Utils/Local.cpp =================================================================== --- llvm/lib/Transforms/Utils/Local.cpp +++ llvm/lib/Transforms/Utils/Local.cpp @@ -58,6 +58,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/IntrinsicsWebAssembly.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Metadata.h" @@ -443,8 +444,23 @@ if (isRemovableAlloc(CB, TLI)) return true; - if (!I->willReturn()) - return false; + if (!I->willReturn()) { + auto *II = dyn_cast(I); + if (!II) + return false; + + // TODO: These intrinsics are not safe to remove, because this may remove + // a well-defined trap. + switch (II->getIntrinsicID()) { + case Intrinsic::wasm_trunc_signed: + case Intrinsic::wasm_trunc_unsigned: + case Intrinsic::ptrauth_auth: + case Intrinsic::ptrauth_resign: + return true; + default: + return false; + } + } if (!I->mayHaveSideEffects()) return true;