[llvm] [SLP] Skip MMRA metadata if instructino can't have it (PR #173319)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 22 15:29:07 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Jinsong Ji (jsji)

<details>
<summary>Changes</summary>

- add test
- skip unsupporte mmras


---
Full diff: https://github.com/llvm/llvm-project/pull/173319.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/VectorUtils.cpp (+4) 
- (added) llvm/test/Transforms/SLPVectorizer/X86/propagate-mmra.ll (+32) 


``````````diff
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index a3e9b039f9225..933e63e956f63 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -1084,6 +1084,10 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
   getMetadataToPropagate(cast<Instruction>(VL[0]), Metadata);
 
   for (auto &[Kind, MD] : Metadata) {
+    // Skip MMRA metadata if the instruction cannot have it.
+    if (Kind == LLVMContext::MD_mmra && !canInstructionHaveMMRAs(*Inst))
+      continue;
+
     for (int J = 1, E = VL.size(); MD && J != E; ++J) {
       const Instruction *IJ = cast<Instruction>(VL[J]);
       MDNode *IMD = IJ->getMetadata(Kind);
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/propagate-mmra.ll b/llvm/test/Transforms/SLPVectorizer/X86/propagate-mmra.ll
new file mode 100644
index 0000000000000..71f502e54d176
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/propagate-mmra.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu -slp-vectorize-hor < %s | FileCheck %s
+
+define void @foo() {
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT:  [[_PREHEADER16_PREHEADER:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = load float, ptr null, align 4, !mmra [[META0:![0-9]+]]
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x float> poison, float [[TMP0]], i32 0
+; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul <2 x float> [[TMP2]], <float 1.000000e+00, float 0.000000e+00>
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd <2 x float> [[TMP3]], zeroinitializer
+; CHECK-NEXT:    [[TMP5:%.*]] = select <2 x i1> zeroinitializer, <2 x float> [[TMP4]], <2 x float> zeroinitializer
+; CHECK-NEXT:    store <2 x float> [[TMP5]], ptr null, align 16
+; CHECK-NEXT:    ret void
+;
+.preheader16.preheader:
+  %0 = load float, ptr null, align 4, !mmra !0
+  %1 = fadd float %0, 0.000000e+00
+  %2 = select i1 false, float %1, float 0.000000e+00
+  store float %2, ptr null, align 16
+  %3 = fmul float %0, 0.000000e+00
+  %4 = fadd float %3, 0.000000e+00
+  %5 = select i1 false, float %4, float 0.000000e+00
+  %.sroa.34.96..sroa_idx = getelementptr i8, ptr null, i64 4
+  store float %5, ptr %.sroa.34.96..sroa_idx, align 4
+  ret void
+}
+
+!0 = !{!"scope", !"device"}
+;.
+; CHECK: [[META0]] = !{!"scope", !"device"}
+;.

``````````

</details>


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


More information about the llvm-commits mailing list