[llvm] Fix: Distinguish CFI Metadata Checks in MergeFunctions Pass (PR #65963)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 11:10:24 PDT 2023


================
@@ -375,9 +375,35 @@ bool MergeFunctions::doFunctionalCheck(std::vector<WeakTrackingVH> &Worklist) {
 }
 #endif
 
+// This function iterates over two functions and compares their
+// metadata to make sure we aren't merging functions which have
+// distinct metadata that is different. We don't care about
+// debug data here, it shouldn't change MIR like CFI would.
+static bool hasDistinctMetadataIntrinsic(const Function &F) {
+  for (const BasicBlock &BB : F) {
+    for (const Instruction &I : BB.instructionsWithoutDebug()) {
+      if (!isa<IntrinsicInst>(&I))
+        continue; // Only intrinsics can reference metadata.
+
+      // Iterate through operands, and return true if you find a distinct
+      // metadata operand.
+      for (unsigned i = 0, e = I.getNumOperands(); i != e;
+           ++i) { // Replaced InstLIt with I
+        MetadataAsValue *MDL = dyn_cast<MetadataAsValue>(
+            I.getOperand(i)); // Replaced InstLIt with I
----------------
nikic wrote:

This seems to bail out on any metadata, not just distinct metadata.

For example, I think this will prevent merging of functions with constrained FP intrinsics, because they use metadata strings as arguments. Could you please add a test to ensure those keep working?

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


More information about the llvm-commits mailing list