Skip to content

Commit 0dd4377

Browse files
authored
[LICM] Fix dropped metadata (#95221)
LICM drops metadata for call instructions when cloning instructions. This patch just adds the missing `copyMetadata`. Fixes #91919.
1 parent a786919 commit 0dd4377

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,7 @@ static Instruction *cloneInstructionInExitBlock(
14531453
}
14541454

14551455
New = CallInst::Create(CI, OpBundles);
1456+
New->copyMetadata(*CI);
14561457
} else {
14571458
New = I.clone();
14581459
}

llvm/test/Transforms/LICM/licm-ci.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -passes=licm < %s | FileCheck %s
3+
4+
define i16 @test(ptr %in) {
5+
; CHECK-LABEL: @test(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: br label [[LOOP:%.*]]
8+
; CHECK: loop:
9+
; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
10+
; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
11+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I_NEXT]], 10
12+
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]]
13+
; CHECK: exit:
14+
; CHECK-NEXT: [[I_LCSSA:%.*]] = phi i32 [ [[I]], [[LOOP]] ]
15+
; CHECK-NEXT: [[GEP_LE:%.*]] = getelementptr <4 x i16>, ptr [[IN:%.*]], i32 [[I_LCSSA]]
16+
; CHECK-NEXT: [[LOAD_LE:%.*]] = call <4 x i16> @llvm.masked.load.v4i16.p0(ptr [[GEP_LE]], i32 2, <4 x i1> <i1 true, i1 false, i1 true, i1 false>, <4 x i16> <i16 0, i16 poison, i16 0, i16 poison>), !alias.scope [[META0:![0-9]+]], !noalias [[META0]]
17+
; CHECK-NEXT: [[REDUCE_LE:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[LOAD_LE]])
18+
; CHECK-NEXT: ret i16 [[REDUCE_LE]]
19+
;
20+
entry:
21+
br label %loop
22+
23+
loop: ; preds = %loop, %entry
24+
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
25+
%gep = getelementptr <4 x i16>, ptr %in, i32 %i
26+
%load = call <4 x i16> @llvm.masked.load.v4i16.p0(ptr %gep, i32 2, <4 x i1> <i1 true, i1 false, i1 true, i1 false>, <4 x i16> <i16 0, i16 poison, i16 0, i16 poison>), !alias.scope !2, !noalias !2
27+
%reduce = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %load)
28+
%i.next = add i32 %i, 1
29+
%cmp = icmp ult i32 %i.next, 10
30+
br i1 %cmp, label %loop, label %exit
31+
32+
exit: ; preds = %loop
33+
ret i16 %reduce
34+
}
35+
36+
!0 = !{!0}
37+
!1 = !{!1, !0}
38+
!2 = !{!1}

0 commit comments

Comments
 (0)