diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/loadstore-aa-metadata.ll | 25 |
2 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index cfdfa00e805..e57091340c0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -319,6 +319,8 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) { 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 *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) { 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; diff --git a/llvm/test/Transforms/InstCombine/loadstore-aa-metadata.ll b/llvm/test/Transforms/InstCombine/loadstore-aa-metadata.ll new file mode 100644 index 00000000000..691f7f8345f --- /dev/null +++ b/llvm/test/Transforms/InstCombine/loadstore-aa-metadata.ll @@ -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 } |