[llvm] [InstCombine] Propagate invariant.load metadata across unpacked loads (PR #152186)
Fei Peng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 14:23:27 PDT 2025
================
@@ -718,6 +718,14 @@ static Instruction *combineLoadToOperationType(InstCombinerImpl &IC,
return nullptr;
}
+// Check if the aggregate load has a invariant.load metadata
+// If aggregate load has invariant.load metadata, add it to the
+// unpacked loads as well.
+static void copyInvariantLoadMetadata(LoadInst &LI, LoadInst *NewLoad) {
+ if (MDNode *MD = LI.getMetadata("invariant.load"))
----------------
fiigii wrote:
`copyMetadataForLoad` sounds like only designed for load type casting. And some code that checks `NewType->isPointerTy()` implicitly assumes the OldType is also a pointer, which sounds incorrect for spliting loads.
```
// Note, essentially every kind of metadata should be preserved here! This
// routine is supposed to clone a load instruction changing *only its type*.
// The only metadata it makes sense to drop is metadata which is invalidated
// when the pointer type changes. This should essentially never be the case
// in LLVM, but we explicitly switch over only known metadata to be
// conservatively correct. If you are adding metadata to LLVM which pertains
// to loads, you almost certainly want to add it here.
```
Shall we add a `copyMetadataForSplitLoad`?
https://github.com/llvm/llvm-project/pull/152186
More information about the llvm-commits
mailing list