[llvm] 0dd4377 - [LICM] Fix dropped metadata (#95221)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 01:22:57 PDT 2024


Author: Tim Gymnich
Date: 2024-06-19T10:22:52+02:00
New Revision: 0dd43774a6bce935f34f9deaf89451cfab34c7ab

URL: https://github.com/llvm/llvm-project/commit/0dd43774a6bce935f34f9deaf89451cfab34c7ab
DIFF: https://github.com/llvm/llvm-project/commit/0dd43774a6bce935f34f9deaf89451cfab34c7ab.diff

LOG: [LICM] Fix dropped metadata (#95221)

LICM drops metadata for call instructions when cloning instructions.
This patch just adds the missing `copyMetadata`.

Fixes #91919.

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

Modified: 
    llvm/lib/Transforms/Scalar/LICM.cpp

Removed: 
    


################################################################################
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();
   }

diff  --git a/llvm/test/Transforms/LICM/licm-ci.ll b/llvm/test/Transforms/LICM/licm-ci.ll
new file mode 100644
index 0000000000000..f16c67f8ea9ad
--- /dev/null
+++ b/llvm/test/Transforms/LICM/licm-ci.ll
@@ -0,0 +1,38 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=licm < %s | FileCheck %s
+
+define i16 @test(ptr %in) {
+; 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 <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>), !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:    ret i16 [[REDUCE_LE]]
+;
+entry:
+  br label %loop
+
+loop:                              ; preds = %loop, %entry
+  %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+  %gep = getelementptr <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
+  ret i16 %reduce
+}
+
+!0 = !{!0}
+!1 = !{!1, !0}
+!2 = !{!1}


        


More information about the llvm-commits mailing list