[PATCH] D150970: [MemCpyOpt] Use memcpy source directly if dest is known to be immutable from attributes

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 03:58:44 PDT 2023


khei4 added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp:1647
+  // Can't handle unknown size alloca (e.g. VLA)
+  if (!AllocaSize)
+    return false;
----------------
nikic wrote:
> khei4 wrote:
> > nikic wrote:
> > > `&& !AllocaSize->isScalable()` (and a test for this)
> > > && !AllocaSize->isScalable()
> > 
> > Sorry, I'm not sure about a scalable vectors pointer could be transformed (maybe `||`, not `&&`?). Do you mean scalable vectors TypeSize are available, but memcpy length cannot be scalable for it, so we couldn't handle it, right?
> Yes, exactly.
Understood. Thanks!


================
Comment at: llvm/test/Transforms/MemCpyOpt/memcpy.ll:467
 ;
   %val1 = alloca %sv
   call void @llvm.memcpy.p0.p0.i64(ptr align 4 %val1, ptr align 4 %val, i64 2, i1 false)
----------------
nikic wrote:
> I'd just write `alloca <vscale x 2 x i32>` here. You're using a "homogeneous scalable aggregate" which also tests the right thing, but is a more advanced feature...
Thanks! Yeah as you said in this case, unnecessary complexity! 


================
Comment at: llvm/test/Transforms/MemCpyOpt/memcpy.ll:527
   ret void
 }
 
----------------
nikic wrote:
> We're missing a test where the alignment can be enforced. For that you want to copy from another alloca with lower alignment, and the alignment will be increased by the transform.
Sorry, I'm not sure how this could be. I now found that MemDepAlign is just memcpy's arguments alignment attributes value, so basically enforcing from parameter attributes works, but I couldn't find the way to enforce lower alignment actually!
(I might too naive, but I tried for example, 
```
@g = global ptr null, align 4

define void @immut_param_enforced_alignment(ptr align 16 noalias %val) {
  %val1 = alloca i8, align 16
  store ptr %val, ptr @g
  %p = load ptr, ptr @g
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %val1, ptr %p, i64 1, i1 false)
  call void @f(ptr nocapture noalias readonly %val1)
  ret void
}
```
this can't enforce the alignment.)



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150970/new/

https://reviews.llvm.org/D150970



More information about the llvm-commits mailing list