[llvm] [LICM] Fix dropped metadata (PR #95221)

Tim Gymnich via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 08:44:26 PDT 2024


https://github.com/tgymnich updated https://github.com/llvm/llvm-project/pull/95221

>From ed2f07a22f7f9b56788c65cf1752e5e057ae62ee Mon Sep 17 00:00:00 2001
From: Tim Gymnich <tgymnich at icloud.com>
Date: Wed, 12 Jun 2024 14:40:54 +0200
Subject: [PATCH 1/3] add test

---
 llvm/test/Transforms/LICM/licm-ci.ll | 40 ++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 llvm/test/Transforms/LICM/licm-ci.ll

diff --git a/llvm/test/Transforms/LICM/licm-ci.ll b/llvm/test/Transforms/LICM/licm-ci.ll
new file mode 100644
index 0000000000000..d7b2403ffaaea
--- /dev/null
+++ b/llvm/test/Transforms/LICM/licm-ci.ll
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=licm < %s | FileCheck %s
+
+define void @test(ptr %in, ptr %out) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LOOP:%.*]]
+; CHECK:       loop:
+; CHECK-NEXT:    [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
+; CHECK-NEXT:    [[I_NEXT]] = add i32 [[I]], 1
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i32 [[I_NEXT]], 10
+; CHECK-NEXT:    br i1 [[CMP]], label [[LOOP]], label [[EXIT:%.*]]
+; CHECK:       exit:
+; CHECK-NEXT:    [[I_LCSSA:%.*]] = phi i32 [ [[I]], [[LOOP]] ]
+; CHECK-NEXT:    [[GEP_LE:%.*]] = getelementptr inbounds <4 x i16>, ptr [[IN:%.*]], i32 [[I_LCSSA]]
+; 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>)
+; CHECK-NEXT:    [[REDUCE_LE:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[LOAD_LE]])
+; CHECK-NEXT:    store i16 [[REDUCE_LE]], ptr [[OUT:%.*]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  br label %loop
+
+loop:                              ; preds = %loop, %entry
+  %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+  %gep = getelementptr inbounds <4 x i16>, ptr %in, i32 %i
+  %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
+  %reduce = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %load)
+  %i.next = add i32 %i, 1
+  %cmp = icmp ult i32 %i.next, 10
+  br i1 %cmp, label %loop, label %exit
+
+exit:                               ; preds = %loop
+  store i16 %reduce, ptr %out, align 4
+  ret void
+}
+
+!0 = !{!0}
+!1 = !{!1, !0}
+!2 = !{!1}

>From 954259759db9c489a810c1e4bc1136e33bbea033 Mon Sep 17 00:00:00 2001
From: Tim Gymnich <tgymnich at icloud.com>
Date: Tue, 11 Jun 2024 23:38:44 +0200
Subject: [PATCH 2/3] Fix dropped metadata in LICM

---
 llvm/lib/Transforms/Scalar/LICM.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 5eccf7b4adb65..75883e0da214d 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1453,6 +1453,7 @@ static Instruction *cloneInstructionInExitBlock(
     }
 
     New = CallInst::Create(CI, OpBundles);
+    New->copyMetadata(*CI);
   } else {
     New = I.clone();
   }

>From bed911b9899836e2eb994a3f9885c50e0acd6ee2 Mon Sep 17 00:00:00 2001
From: Tim Gymnich <tgymnich at icloud.com>
Date: Wed, 12 Jun 2024 14:57:13 +0200
Subject: [PATCH 3/3] update test

---
 llvm/test/Transforms/LICM/licm-ci.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/Transforms/LICM/licm-ci.ll b/llvm/test/Transforms/LICM/licm-ci.ll
index d7b2403ffaaea..fe9e1cc53a8c8 100644
--- a/llvm/test/Transforms/LICM/licm-ci.ll
+++ b/llvm/test/Transforms/LICM/licm-ci.ll
@@ -13,7 +13,7 @@ define void @test(ptr %in, ptr %out) {
 ; CHECK:       exit:
 ; CHECK-NEXT:    [[I_LCSSA:%.*]] = phi i32 [ [[I]], [[LOOP]] ]
 ; CHECK-NEXT:    [[GEP_LE:%.*]] = getelementptr inbounds <4 x i16>, ptr [[IN:%.*]], i32 [[I_LCSSA]]
-; 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>)
+; 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]]
 ; CHECK-NEXT:    [[REDUCE_LE:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[LOAD_LE]])
 ; CHECK-NEXT:    store i16 [[REDUCE_LE]], ptr [[OUT:%.*]], align 4
 ; CHECK-NEXT:    ret void



More information about the llvm-commits mailing list