[PATCH] D136201: [InstCombine] Handle PHI nodes when eliminating constant memcpy
Anshil Gandhi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 31 14:29:27 PDT 2022
gandhi21299 added a comment.
In D136201#3896724 <https://reviews.llvm.org/D136201#3896724>, @nikic wrote:
>> 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.
It compiles correctly. The output does not differ from the input at all.
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