Reapply [FunctionAttrs] Make location classification more precise
authorNikita Popov <npopov@redhat.com>
Wed, 19 Oct 2022 14:57:41 +0000 (16:57 +0200)
committerNikita Popov <npopov@redhat.com>
Thu, 20 Oct 2022 13:13:20 +0000 (15:13 +0200)
Reapplying after the fix for volatile modelling in D135863.

-----

Don't add argmem if the pointer is clearly not an argument (e.g.
a global). I don't think this makes a difference right now, but
gives more obvious results with D135780.

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

index 7ca76ad..932feea 100644 (file)
@@ -145,11 +145,17 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
       return;
 
     const Value *UO = getUnderlyingObject(Loc.Ptr);
-    // The accessed location can be either only argument memory, or
-    // argument & other memory, but never inaccessible memory.
-    ME |= MemoryEffects::argMemOnly(MR);
-    if (!isa<Argument>(UO) && !isa<AllocaInst>(UO))
-      ME |= MemoryEffects(MemoryEffects::Other, MR);
+    assert(!isa<AllocaInst>(UO) &&
+           "Should have been handled by pointsToConstantMemory()");
+    if (isa<Argument>(UO)) {
+      ME |= MemoryEffects::argMemOnly(MR);
+      return;
+    }
+
+    // If it's not an identified object, it might be an argument.
+    if (!isIdentifiedObject(UO))
+      ME |= MemoryEffects::argMemOnly(MR);
+    ME |= MemoryEffects(MemoryEffects::Other, MR);
   };
   // Scan the function body for instructions that may read or write memory.
   for (Instruction &I : instructions(F)) {