Skip to content

Commit 0b20c30

Browse files
committed
[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
1 parent eaea460 commit 0b20c30

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

llvm/lib/IR/Instruction.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,7 @@ bool Instruction::willReturn() const {
744744
return !SI->isVolatile();
745745

746746
if (const auto *CB = dyn_cast<CallBase>(this))
747-
// FIXME: Temporarily assume that all side-effect free intrinsics will
748-
// return. Remove this workaround once all intrinsics are appropriately
749-
// annotated.
750-
return CB->hasFnAttr(Attribute::WillReturn) ||
751-
(isa<IntrinsicInst>(CB) && CB->onlyReadsMemory());
747+
return CB->hasFnAttr(Attribute::WillReturn);
752748
return true;
753749
}
754750

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/IR/Instructions.h"
5959
#include "llvm/IR/IntrinsicInst.h"
6060
#include "llvm/IR/Intrinsics.h"
61+
#include "llvm/IR/IntrinsicsWebAssembly.h"
6162
#include "llvm/IR/LLVMContext.h"
6263
#include "llvm/IR/MDBuilder.h"
6364
#include "llvm/IR/Metadata.h"
@@ -444,8 +445,24 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I,
444445
if (isRemovableAlloc(CB, TLI))
445446
return true;
446447

447-
if (!I->willReturn())
448-
return false;
448+
if (!I->willReturn()) {
449+
auto *II = dyn_cast<IntrinsicInst>(I);
450+
if (!II)
451+
return false;
452+
453+
// TODO: These intrinsics are not safe to remove, because this may remove
454+
// a well-defined trap.
455+
switch (II->getIntrinsicID()) {
456+
case Intrinsic::wasm_trunc_signed:
457+
case Intrinsic::wasm_trunc_unsigned:
458+
case Intrinsic::ptrauth_auth:
459+
case Intrinsic::ptrauth_resign:
460+
case Intrinsic::ptrauth_sign:
461+
return true;
462+
default:
463+
return false;
464+
}
465+
}
449466

450467
if (!I->mayHaveSideEffects())
451468
return true;

0 commit comments

Comments
 (0)