[llvm] [EarlyCSE] De-Duplicate callsites with differing attrs (PR #110929)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 07:32:34 PDT 2024


================
@@ -1307,6 +1307,23 @@ static void combineIRFlags(Instruction &From, Value *To) {
         (I->hasPoisonGeneratingFlags() && !programUndefinedIfPoison(I)))
       I->andIRFlags(&From);
   }
+  if (isa<CallBase>(&From) && isa<CallBase>(To)) {
+    // NB: Intersection of attrs between InVal.first and Inst is overly
+    // conservative. Since we only CSE readonly functions that have the same
+    // memory state, we can preserve (or possibly in some cases combine)
+    // more attributes. Likewise this implies when checking equality of
+    // callsite for CSEing, we can probably ignore more attributes.
+    // Generally poison generating attributes need to be handled with more
+    // care as they can create *new* UB if preserved/combined and violated.
+    // Attributes that imply immediate UB on the otherhand would have been
+    // violated either way.
+    bool Success =
+        cast<CallBase>(To)->tryIntersectAttributes(cast<CallBase>(&From));
+    assert(Success && "Failed to intersect attributes in callsites that "
+                      "passed identical check");
+    // For NDEBUG Compile.
+    (void)Success;
----------------
goldsteinn wrote:

I tend to prefer the `(void)X`. Although not religiously.

https://github.com/llvm/llvm-project/pull/110929


More information about the llvm-commits mailing list