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

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 7 04:01:30 PDT 2023


nikic added inline comments.


================
Comment at: llvm/test/Transforms/MemCpyOpt/memcpy.ll:527
   ret void
 }
 
----------------
khei4 wrote:
> 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.)
> 
I believe you need something like this:
```
define void @test() {
  %val = alloca i8, align 1
  store i32 42, ptr %val
  %val1 = alloca i8, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr %val1, ptr %val, i64 1, i1 false)
  call void @f_full_readonly(ptr %val1)
  ret void
}
```
Here the `align 1` on the first alloca will be changed to `align 4` by the transform.


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

https://reviews.llvm.org/D150970



More information about the llvm-commits mailing list