[llvm] 0b20c30 - [IR] Don't assume readnone/readonly intrinsics are willreturn
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 6 02:48:58 PST 2022
Author: Nikita Popov
Date: 2022-12-06T11:48:50+01:00
New Revision: 0b20c3034c9cef2c0fdbfdfba1d4dfa0761a014f
URL: https://github.com/llvm/llvm-project/commit/0b20c3034c9cef2c0fdbfdfba1d4dfa0761a014f
DIFF: https://github.com/llvm/llvm-project/commit/0b20c3034c9cef2c0fdbfdfba1d4dfa0761a014f.diff
LOG: [IR] Don't assume readnone/readonly intrinsics are willreturn
This removes our "temporary" hack to assume that readnone/readonly
intrinsics are also willreturn. An explicit willreturn annotation,
usually via default intrinsic attributes, is now required.
Differential Revision: https://reviews.llvm.org/D137630
Added:
Modified:
llvm/lib/IR/Instruction.cpp
llvm/lib/Transforms/Utils/Local.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 3988054f33bd2..bd89b3e0c2cc9 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -744,11 +744,7 @@ bool Instruction::willReturn() const {
return !SI->isVolatile();
if (const auto *CB = dyn_cast<CallBase>(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<IntrinsicInst>(CB) && CB->onlyReadsMemory());
+ return CB->hasFnAttr(Attribute::WillReturn);
return true;
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 819ad08e0552b..8be5b4b8eb7e2 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/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"
@@ -444,8 +445,24 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I,
if (isRemovableAlloc(CB, TLI))
return true;
- if (!I->willReturn())
- return false;
+ if (!I->willReturn()) {
+ auto *II = dyn_cast<IntrinsicInst>(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:
+ case Intrinsic::ptrauth_sign:
+ return true;
+ default:
+ return false;
+ }
+ }
if (!I->mayHaveSideEffects())
return true;
More information about the llvm-commits
mailing list