[llvm] 12e14bc - [Attributor] Make non-side-effect inline asm be "no-call"

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 20:56:32 PST 2022


Author: Johannes Doerfert
Date: 2022-12-12T20:55:35-08:00
New Revision: 12e14bc42b1500b4a9b02357dea7c6158a0b714d

URL: https://github.com/llvm/llvm-project/commit/12e14bc42b1500b4a9b02357dea7c6158a0b714d
DIFF: https://github.com/llvm/llvm-project/commit/12e14bc42b1500b4a9b02357dea7c6158a0b714d.diff

LOG: [Attributor] Make non-side-effect inline asm be "no-call"

If we have inline asm with side effects we assume any function might be
called. For non-side-effect asm we now assume no function is called.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/nosync.ll
    llvm/test/Transforms/Attributor/reachability.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index b5ca98d811a1b..0c16fbd1f7702 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -44,6 +44,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/GlobalValue.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -9665,10 +9666,12 @@ struct AACallEdgesCallSite : public AACallEdgesImpl {
 
     CallBase *CB = cast<CallBase>(getCtxI());
 
-    if (CB->isInlineAsm()) {
-      if (!hasAssumption(*CB->getCaller(), "ompx_no_call_asm") &&
-          !hasAssumption(*CB, "ompx_no_call_asm"))
+    if (auto *IA = dyn_cast<InlineAsm>(CB->getCalledOperand())) {
+      if (IA->hasSideEffects() &&
+          !hasAssumption(*CB->getCaller(), "ompx_no_call_asm") &&
+          !hasAssumption(*CB, "ompx_no_call_asm")) {
         setHasUnknownCallee(false, Change);
+      }
       return Change;
     }
 

diff  --git a/llvm/test/Transforms/Attributor/nosync.ll b/llvm/test/Transforms/Attributor/nosync.ll
index 324c49fe0151c..1133cdfeff3ad 100644
--- a/llvm/test/Transforms/Attributor/nosync.ll
+++ b/llvm/test/Transforms/Attributor/nosync.ll
@@ -379,10 +379,10 @@ define i32 @memset_non_volatile(i8* %ptr1, i8 %val) {
 define i32 @inline_asm_test(i32 %x) {
 ; CHECK-LABEL: define {{[^@]+}}@inline_asm_test
 ; CHECK-SAME: (i32 [[X:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = call i32 asm "bswap $0", "=r,r"(i32 [[X]])
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 asm sideeffect "bswap $0", "=r,r"(i32 [[X]])
 ; CHECK-NEXT:    ret i32 4
 ;
-  call i32 asm "bswap $0", "=r,r"(i32 %x)
+  call i32 asm sideeffect "bswap $0", "=r,r"(i32 %x)
   ret i32 4
 }
 

diff  --git a/llvm/test/Transforms/Attributor/reachability.ll b/llvm/test/Transforms/Attributor/reachability.ll
index 76c448c16025e..0852479a50266 100644
--- a/llvm/test/Transforms/Attributor/reachability.ll
+++ b/llvm/test/Transforms/Attributor/reachability.ll
@@ -28,6 +28,19 @@ entry:
   ret void
 }
 
+define void @non_recursive_asm_no_sideffect() {
+; CHECK: Function Attrs: norecurse
+; CHECK-LABEL: define {{[^@]+}}@non_recursive_asm_no_sideffect
+; CHECK-SAME: () #[[ATTR1]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    call void asm "foobar
+; CHECK-NEXT:    ret void
+;
+entry:
+  call void asm "foobar;", ""()
+  ret void
+}
+
 define void @recursive_asm() {
 ; CHECK-LABEL: define {{[^@]+}}@recursive_asm() {
 ; CHECK-NEXT:  entry:


        


More information about the llvm-commits mailing list