[PATCH] D136201: [InstCombine] Handle PHI nodes when eliminating constant memcpy

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 09:44:29 PDT 2022


nikic added a comment.

> I believe the change to isOnlyCopiedFromConstantMemory() is fine

I think I spoke too soon ... I can't test this right now, but probably this minor variant is going to be miscompiled:

  define i32 @test1(i1 %c, ptr %ptr) {
  entry:
    %a = alloca [32 x i8]
    br i1 %c, label %if, label %join
  
  if:
    br label %join
  
  join:
    %phi = phi ptr [ %a, %if ], [ %ptr, %entry ]
    call void @llvm.memcpy.p0.p0.i64(ptr %phi, ptr @g1, i64 32, i1 false)
    %v = load i32, ptr %phi
    ret i32 %v
  }

While we can replace uses of `%a` with `@g1`, dropping the memcpy would be incorrect, as it would also drop the potential write to `%ptr`, which is not covered by the replacement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136201



More information about the llvm-commits mailing list