[llvm] [InstCombine] Allow load to store forwarding for scalable structs (PR #123908)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 01:57:20 PST 2025


================
@@ -572,6 +573,19 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
     if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
       return Val;
 
+    if (AllowPartwiseBitcastStructs) {
+      if (StructType *SrcStructTy = dyn_cast<StructType>(Val->getType())) {
+        if (StructType *DestStructTy = dyn_cast<StructType>(AccessTy)) {
+          if (SrcStructTy->getNumElements() == DestStructTy->getNumElements() &&
+              all_of_zip(SrcStructTy->elements(), DestStructTy->elements(),
+                         [](Type *T1, Type *T2) {
+                           return CastInst::isBitCastable(T1, T2);
+                         }))
+            return Val;
+        }
+      }
+    }
----------------
nikic wrote:

I think this may handle the case where the struct members are bitcastable but have different offsets because of different member alignment incorrectly?

https://github.com/llvm/llvm-project/pull/123908


More information about the llvm-commits mailing list