[llvm] r220141 - Preserve AA metadata when combining (cast (load (...))) -> (load (cast

Hal Finkel hfinkel at anl.gov
Sat Oct 18 23:48:49 PDT 2014


----- Original Message -----
> From: "Chandler Carruth" <chandlerc at gmail.com>
> To: llvm-commits at cs.uiuc.edu
> Sent: Saturday, October 18, 2014 6:00:12 AM
> Subject: [llvm] r220141 - Preserve AA metadata when combining (cast (load	(...))) -> (load (cast
> 
> Author: chandlerc
> Date: Sat Oct 18 06:00:12 2014
> New Revision: 220141
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=220141&view=rev
> Log:
> Preserve AA metadata when combining (cast (load (...))) -> (load
> (cast
> (...))).

This is obviously good, but there is also other metadata that can be preserved here (like llvm.mem.parallel_loop_access, invariant.load, etc.), and we should do so. I think that it might be better to "drop and copy" instead of doing it this way. We have a Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) function now which should make this easy.

 -Hal

> 
> Added:
>     llvm/trunk/test/Transforms/InstCombine/loadstore-aa-metadata.ll
> Modified:
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> 
> Modified:
> llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=220141&r1=220140&r2=220141&view=diff
> ==============================================================================
> ---
> llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> (original)
> +++
> llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> Sat Oct 18 06:00:12 2014
> @@ -319,6 +319,8 @@ static Instruction *combineLoadToOperati
>  
>    Value *Ptr = LI.getPointerOperand();
>    unsigned AS = LI.getPointerAddressSpace();
> +  AAMDNodes AAInfo;
> +  LI.getAAMetadata(AAInfo);
>  
>    // Fold away bit casts of the loaded value by loading the desired
>    type.
>    if (LI.hasOneUse())
> @@ -326,6 +328,7 @@ static Instruction *combineLoadToOperati
>        LoadInst *NewLoad = IC.Builder->CreateAlignedLoad(
>            IC.Builder->CreateBitCast(Ptr,
>            BC->getDestTy()->getPointerTo(AS)),
>            LI.getAlignment(), LI.getName());
> +      NewLoad->setAAMetadata(AAInfo);
>        BC->replaceAllUsesWith(NewLoad);
>        IC.EraseInstFromFunction(*BC);
>        return &LI;
> 
> Added:
> llvm/trunk/test/Transforms/InstCombine/loadstore-aa-metadata.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/loadstore-aa-metadata.ll?rev=220141&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/loadstore-aa-metadata.ll
> (added)
> +++ llvm/trunk/test/Transforms/InstCombine/loadstore-aa-metadata.ll
> Sat Oct 18 06:00:12 2014
> @@ -0,0 +1,25 @@
> +; RUN: opt -instcombine -S < %s | FileCheck %s
> +
> +define i32 @test_load_cast_combine_tbaa(float* %ptr) {
> +; Ensure (cast (load (...))) -> (load (cast (...))) preserves TBAA.
> +; CHECK-LABEL: @test_load_cast_combine_tbaa(
> +; CHECK: load i32* %{{.*}}, !tbaa !0
> +entry:
> +  %l = load float* %ptr, !tbaa !0
> +  %c = bitcast float %l to i32
> +  ret i32 %c
> +}
> +
> +define i32 @test_load_cast_combine_noalias(float* %ptr) {
> +; Ensure (cast (load (...))) -> (load (cast (...))) preserves
> no-alias metadata.
> +; CHECK-LABEL: @test_load_cast_combine_noalias(
> +; CHECK: load i32* %{{.*}}, !alias.scope !2, !noalias !1
> +entry:
> +  %l = load float* %ptr, !alias.scope !2, !noalias !1
> +  %c = bitcast float %l to i32
> +  ret i32 %c
> +}
> +
> +!0 = metadata !{ metadata !1, metadata !1, i64 0 }
> +!1 = metadata !{ metadata !1 }
> +!2 = metadata !{ metadata !2, metadata !1 }
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list