[PATCH] D137630: [IR] Don't assume readnone/readonly intrinsics are willreturn

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 03:51:08 PST 2022


nikic created this revision.
nikic added reviewers: jdoerfert, fhahn.
Herald added subscribers: hiraditya, dschuff.
Herald added a project: All.
nikic requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

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.

Depends on D137557 <https://reviews.llvm.org/D137557>, D137623 <https://reviews.llvm.org/D137623>, D137629 <https://reviews.llvm.org/D137629>.


https://reviews.llvm.org/D137630

Files:
  llvm/lib/IR/Instruction.cpp
  llvm/lib/Transforms/Utils/Local.cpp


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<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:
+      return true;
+    default:
+      return false;
+    }
+  }
 
   if (!I->mayHaveSideEffects())
     return true;
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<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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137630.473949.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/e15a96dc/attachment.bin>


More information about the llvm-commits mailing list