mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Make gep i8* X, -(ptrtoint Y) transform work with address spaces
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d6370ad87d
commit
1df59ef1aa
@ -1186,14 +1186,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
// The GEP pattern is emitted by the SCEV expander for certain kinds of
|
||||
// pointer arithmetic.
|
||||
if (TD && GEP.getNumIndices() == 1 &&
|
||||
match(GEP.getOperand(1), m_Neg(m_PtrToInt(m_Value()))) &&
|
||||
GEP.getType() == Builder->getInt8PtrTy() &&
|
||||
GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
|
||||
TD->getPointerSizeInBits(GEP.getPointerAddressSpace())) {
|
||||
Operator *Index = cast<Operator>(GEP.getOperand(1));
|
||||
Value *PtrToInt = Builder->CreatePtrToInt(PtrOp, Index->getType());
|
||||
Value *NewSub = Builder->CreateSub(PtrToInt, Index->getOperand(1));
|
||||
return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
|
||||
match(GEP.getOperand(1), m_Neg(m_PtrToInt(m_Value())))) {
|
||||
unsigned AS = GEP.getPointerAddressSpace();
|
||||
if (GEP.getType() == Builder->getInt8PtrTy(AS) &&
|
||||
GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
|
||||
TD->getPointerSizeInBits(AS)) {
|
||||
Operator *Index = cast<Operator>(GEP.getOperand(1));
|
||||
Value *PtrToInt = Builder->CreatePtrToInt(PtrOp, Index->getType());
|
||||
Value *NewSub = Builder->CreateSub(PtrToInt, Index->getOperand(1));
|
||||
return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
|
||||
}
|
||||
}
|
||||
|
||||
// Handle gep(bitcast x) and gep(gep x, 0, 0, 0).
|
||||
|
@ -776,4 +776,17 @@ define i64 @test40() {
|
||||
; CHECK-NEXT: ret i64 8
|
||||
}
|
||||
|
||||
define i16 @test41([3 x i32] addrspace(1)* %array) {
|
||||
%gep = getelementptr inbounds [3 x i32] addrspace(1)* %array, i16 0, i16 2
|
||||
%gepi8 = bitcast i32 addrspace(1)* %gep to i8 addrspace(1)*
|
||||
%p = ptrtoint [3 x i32] addrspace(1)* %array to i16
|
||||
%np = sub i16 0, %p
|
||||
%gep2 = getelementptr i8 addrspace(1)* %gepi8, i16 %np
|
||||
%ret = ptrtoint i8 addrspace(1)* %gep2 to i16
|
||||
ret i16 %ret
|
||||
|
||||
; CHECK-LABEL: @test41(
|
||||
; CHECK-NEXT: ret i16 8
|
||||
}
|
||||
|
||||
; CHECK: attributes [[NUW]] = { nounwind }
|
||||
|
Loading…
x
Reference in New Issue
Block a user