mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-23 04:28:30 +00:00
Preserve AA metadata when combining (cast (load (...))) -> (load (cast
(...))). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220141 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9b2d091a9c
commit
797e9b812e
@ -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;
|
||||
|
25
test/Transforms/InstCombine/loadstore-aa-metadata.ll
Normal file
25
test/Transforms/InstCombine/loadstore-aa-metadata.ll
Normal file
@ -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 }
|
Loading…
Reference in New Issue
Block a user