mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-14 09:38:40 +00:00
Fix PR19270 - type mismatch caused by invalid optimization.
Patch by Jingyue Wu. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205547 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1c36a6d8e7
commit
1fcd561c73
@ -1241,7 +1241,15 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
GetElementPtrInst *Res =
|
GetElementPtrInst *Res =
|
||||||
GetElementPtrInst::Create(StrippedPtr, Idx, GEP.getName());
|
GetElementPtrInst::Create(StrippedPtr, Idx, GEP.getName());
|
||||||
Res->setIsInBounds(GEP.isInBounds());
|
Res->setIsInBounds(GEP.isInBounds());
|
||||||
return Res;
|
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace())
|
||||||
|
return Res;
|
||||||
|
// Insert Res, and create an addrspacecast.
|
||||||
|
// e.g.,
|
||||||
|
// GEP (addrspacecast i8 addrspace(1)* X to [0 x i8]*), i32 0, ...
|
||||||
|
// ->
|
||||||
|
// %0 = GEP i8 addrspace(1)* X, ...
|
||||||
|
// addrspacecast i8 addrspace(1)* %0 to i8*
|
||||||
|
return new AddrSpaceCastInst(Builder->Insert(Res), GEP.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ArrayType *XATy =
|
if (ArrayType *XATy =
|
||||||
@ -1253,8 +1261,24 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
// to an array of the same type as the destination pointer
|
// to an array of the same type as the destination pointer
|
||||||
// array. Because the array type is never stepped over (there
|
// array. Because the array type is never stepped over (there
|
||||||
// is a leading zero) we can fold the cast into this GEP.
|
// is a leading zero) we can fold the cast into this GEP.
|
||||||
GEP.setOperand(0, StrippedPtr);
|
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
|
||||||
return &GEP;
|
GEP.setOperand(0, StrippedPtr);
|
||||||
|
return &GEP;
|
||||||
|
}
|
||||||
|
// Cannot replace the base pointer directly because StrippedPtr's
|
||||||
|
// address space is different. Instead, create a new GEP followed by
|
||||||
|
// an addrspacecast.
|
||||||
|
// e.g.,
|
||||||
|
// GEP (addrspacecast [10 x i8] addrspace(1)* X to [0 x i8]*),
|
||||||
|
// i32 0, ...
|
||||||
|
// ->
|
||||||
|
// %0 = GEP [10 x i8] addrspace(1)* X, ...
|
||||||
|
// addrspacecast i8 addrspace(1)* %0 to i8*
|
||||||
|
SmallVector<Value*, 8> Idx(GEP.idx_begin(), GEP.idx_end());
|
||||||
|
Value *NewGEP = GEP.isInBounds() ?
|
||||||
|
Builder->CreateInBoundsGEP(StrippedPtr, Idx, GEP.getName()) :
|
||||||
|
Builder->CreateGEP(StrippedPtr, Idx, GEP.getName());
|
||||||
|
return new AddrSpaceCastInst(NewGEP, GEP.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: opt < %s -instcombine -S
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||||
|
|
||||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
||||||
target triple = "x86_64-pc-win32"
|
target triple = "x86_64-pc-win32"
|
||||||
@ -17,3 +17,18 @@ ST:
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@array = internal addrspace(3) global [256 x float] zeroinitializer, align 4
|
||||||
|
@scalar = internal addrspace(3) global float 0.000000e+00, align 4
|
||||||
|
|
||||||
|
define void @keep_necessary_addrspacecast(i64 %i, float** %out0, float** %out1) {
|
||||||
|
entry:
|
||||||
|
; CHECK-LABEL: @keep_necessary_addrspacecast
|
||||||
|
%0 = getelementptr [256 x float]* addrspacecast ([256 x float] addrspace(3)* @array to [256 x float]*), i64 0, i64 %i
|
||||||
|
; CHECK: addrspacecast float addrspace(3)* %{{[0-9]+}} to float*
|
||||||
|
%1 = getelementptr [0 x float]* addrspacecast (float addrspace(3)* @scalar to [0 x float]*), i64 0, i64 %i
|
||||||
|
; CHECK: addrspacecast float addrspace(3)* %{{[0-9]+}} to float*
|
||||||
|
store float* %0, float** %out0, align 4
|
||||||
|
store float* %1, float** %out1, align 4
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user