[llvm] r283165 - Make GlobalsAA ignore dead constant expressions.

Friedman, Eli via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 09:41:37 PDT 2016


On 10/21/2016 7:27 AM, Oliver Stannard wrote:
> Hi Eli,
>
> I've found a codegen regression (using csmith), and bisected it back to this commit. Here's the minimal reproducer for it:
>
>    @c = internal global i32 1, align 4
>    @d = hidden global i32* @c, align 4
>    @f = hidden global i32* @c, align 4
>    @e = hidden global i32 0, align 4
>    @.str = private unnamed_addr constant [15 x i8] c"checksum = %X\0A\00", align 1
>
>    define void @main() {
>    entry:
>      %0 = load i32, i32* @c, align 4
>      store i32 %0, i32* @e, align 4
>      %1 = load i32*, i32** @d, align 4
>      store i32 2, i32* %1, align 4
>      %2 = load i32, i32* @c, align 4
>      %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), i32 %2) #2
>      ret void
>    }
>
>    declare i32 @printf(i8* nocapture readonly, ...)
>
> This gets miscompiled when globals-aa is used in combination with instcombine:
>
>    $ /work/llvm/build/bin/opt -globals-aa -instcombine < test.ll -S
>    ; ModuleID = '<stdin>'
>    source_filename = "<stdin>"
>
>    @c = internal global i32 1, align 4
>    @d = hidden global i32* @c, align 8
>    @f = hidden global i32* @c, align 4
>    @e = hidden global i32 0, align 4
>    @.str = private unnamed_addr constant [15 x i8] c"checksum = %X\0A\00", align 1
>
>    define void @main() {
>    entry:
>      %0 = load i32, i32* @c, align 4
>      store i32 %0, i32* @e, align 4
>      %1 = load i32*, i32** @d, align 8
>      store i32 2, i32* %1, align 4
>      %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
>      ret void
>    }
>
>    declare i32 @printf(i8* nocapture readonly, ...)
>
> The second parameter to the printf call has been replaced with %0, which is the value loaded from @c before @c was modified by the store through pointer @d/%1.
>
> Sorry it's taken me so long to report this, it had been masked by some other issues until recently.
Probably fixed by https://reviews.llvm.org/D25798 .

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-commits mailing list