Skip to content

Commit 4ef602d

Browse files
authored
[SLP] Skip MMRA metadata if instruction can't have it (#173319)
Exposed by recent commit in e644f06, but the wrong propagation might be applied in other situations too. Without this, we will get verification errors with e644f06. !mmra metadata attached to unexpected instruction kind %3 = fmul <2 x float> %2, <float 1.000000e+00, float 0.000000e+00>, !mmra !1
1 parent e3ef26d commit 4ef602d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,10 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
10841084
getMetadataToPropagate(cast<Instruction>(VL[0]), Metadata);
10851085

10861086
for (auto &[Kind, MD] : Metadata) {
1087+
// Skip MMRA metadata if the instruction cannot have it.
1088+
if (Kind == LLVMContext::MD_mmra && !canInstructionHaveMMRAs(*Inst))
1089+
continue;
1090+
10871091
for (int J = 1, E = VL.size(); MD && J != E; ++J) {
10881092
const Instruction *IJ = cast<Instruction>(VL[J]);
10891093
MDNode *IMD = IJ->getMetadata(Kind);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown -slp-vectorize-hor < %s | FileCheck %s
3+
4+
define void @foo() {
5+
; CHECK-LABEL: define void @foo() {
6+
; CHECK-NEXT: [[_PREHEADER16_PREHEADER:.*:]]
7+
; CHECK-NEXT: [[TMP0:%.*]] = load float, ptr null, align 4, !mmra [[META0:![0-9]+]]
8+
; CHECK-NEXT: [[TMP2:%.*]] = fmul float [[TMP0]], 0.000000e+00
9+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[TMP0]], i32 0
10+
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <2 x float> [[TMP1]], float [[TMP2]], i32 1
11+
; CHECK-NEXT: [[TMP4:%.*]] = fadd <2 x float> [[TMP3]], zeroinitializer
12+
; CHECK-NEXT: [[TMP5:%.*]] = select <2 x i1> zeroinitializer, <2 x float> [[TMP4]], <2 x float> zeroinitializer
13+
; CHECK-NEXT: store <2 x float> [[TMP5]], ptr null, align 16
14+
; CHECK-NEXT: ret void
15+
;
16+
.preheader16.preheader:
17+
%0 = load float, ptr null, align 4, !mmra !0
18+
%1 = fadd float %0, 0.000000e+00
19+
%2 = select i1 false, float %1, float 0.000000e+00
20+
store float %2, ptr null, align 16
21+
%3 = fmul float %0, 0.000000e+00
22+
%4 = fadd float %3, 0.000000e+00
23+
%5 = select i1 false, float %4, float 0.000000e+00
24+
%.sroa.34.96..sroa_idx = getelementptr i8, ptr null, i64 4
25+
store float %5, ptr %.sroa.34.96..sroa_idx, align 4
26+
ret void
27+
}
28+
29+
!0 = !{!"scope", !"device"}
30+
;.
31+
; CHECK: [[META0]] = !{!"scope", !"device"}
32+
;.

0 commit comments

Comments
 (0)