nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC doesn't CSE inline asm when 'p' is used on inputs, neither should
clang. In order to do so, we must not set memory(none) modref on such
inline asm.

If you're passing the address of a variable into inline asm as an
operand, you're going to be reading memory!

Link: 
https://lore.kernel.org/lkml/20230306120106.ge1267...@hirez.programming.kicks-ass.net/


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145416

Files:
  clang/lib/Basic/TargetInfo.cpp
  clang/test/CodeGen/inline-asm-p-constraint.c


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===================================================================
--- clang/test/CodeGen/inline-asm-p-constraint.c
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -11,5 +11,4 @@
   asm ("":"=r"(x):"p"(&current_task));
 }
 // CHECK: %0 = call i64 asm "", "=r,r"(ptr @current_task) #[[ATTR:[0-9]+]]
-// FIXME: should be memory(read)
-// CHECK: attributes #[[ATTR]] = { nounwind memory(none) }
+// CHECK: attributes #[[ATTR]] = { nounwind memory(read) }
Index: clang/lib/Basic/TargetInfo.cpp
===================================================================
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -896,14 +896,13 @@
       Info.setAllowsMemory();
       break;
     case 'g': // general register, memory operand or immediate integer.
+    case 'p': // address operand.
     case 'X': // any operand.
       Info.setAllowsRegister();
       Info.setAllowsMemory();
       break;
     case 'E': // immediate floating point.
     case 'F': // immediate floating point.
-    case 'p': // address operand.
-      break;
     case ',': // multiple alternative constraint.  Ignore comma.
       break;
     case '#': // Ignore as constraint.


Index: clang/test/CodeGen/inline-asm-p-constraint.c
===================================================================
--- clang/test/CodeGen/inline-asm-p-constraint.c
+++ clang/test/CodeGen/inline-asm-p-constraint.c
@@ -11,5 +11,4 @@
   asm ("":"=r"(x):"p"(&current_task));
 }
 // CHECK: %0 = call i64 asm "", "=r,r"(ptr @current_task) #[[ATTR:[0-9]+]]
-// FIXME: should be memory(read)
-// CHECK: attributes #[[ATTR]] = { nounwind memory(none) }
+// CHECK: attributes #[[ATTR]] = { nounwind memory(read) }
Index: clang/lib/Basic/TargetInfo.cpp
===================================================================
--- clang/lib/Basic/TargetInfo.cpp
+++ clang/lib/Basic/TargetInfo.cpp
@@ -896,14 +896,13 @@
       Info.setAllowsMemory();
       break;
     case 'g': // general register, memory operand or immediate integer.
+    case 'p': // address operand.
     case 'X': // any operand.
       Info.setAllowsRegister();
       Info.setAllowsMemory();
       break;
     case 'E': // immediate floating point.
     case 'F': // immediate floating point.
-    case 'p': // address operand.
-      break;
     case ',': // multiple alternative constraint.  Ignore comma.
       break;
     case '#': // Ignore as constraint.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to