1
0
mirror of https://github.com/c64scene-ar/llvm-6502.git synced 2025-01-18 13:34:04 +00:00

InstCombine: Fix and simplify the inttoptr side too.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174438 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-02-05 20:22:40 +00:00
parent 07b884af25
commit 39b5f12dd6
2 changed files with 24 additions and 13 deletions
lib/Transforms/InstCombine
test/Transforms/InstCombine

@ -1322,19 +1322,14 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) {
// If the source integer type is not the intptr_t type for this target, do a // If the source integer type is not the intptr_t type for this target, do a
// trunc or zext to the intptr_t type, then inttoptr of it. This allows the // trunc or zext to the intptr_t type, then inttoptr of it. This allows the
// cast to be exposed to other transforms. // cast to be exposed to other transforms.
if (TD) { if (TD && CI.getOperand(0)->getType()->getScalarSizeInBits() !=
if (CI.getOperand(0)->getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) {
TD->getPointerSizeInBits()) { Type *Ty = TD->getIntPtrType(CI.getContext());
Value *P = Builder->CreateTrunc(CI.getOperand(0), if (CI.getType()->isVectorTy()) // Handle vectors of pointers.
TD->getIntPtrType(CI.getContext())); Ty = VectorType::get(Ty, CI.getType()->getVectorNumElements());
return new IntToPtrInst(P, CI.getType());
} Value *P = Builder->CreateZExtOrTrunc(CI.getOperand(0), Ty);
if (CI.getOperand(0)->getType()->getScalarSizeInBits() < return new IntToPtrInst(P, CI.getType());
TD->getPointerSizeInBits()) {
Value *P = Builder->CreateZExt(CI.getOperand(0),
TD->getIntPtrType(CI.getContext()));
return new IntToPtrInst(P, CI.getType());
}
} }
if (Instruction *I = commonCastTransforms(CI)) if (Instruction *I = commonCastTransforms(CI))

@ -42,3 +42,19 @@ define <4 x i128> @test5(<4 x i8*> %arg) nounwind {
%p1 = ptrtoint <4 x i8*> %arg to <4 x i128> %p1 = ptrtoint <4 x i8*> %arg to <4 x i128>
ret <4 x i128> %p1 ret <4 x i128> %p1
} }
define <4 x i8*> @test6(<4 x i32> %arg) nounwind {
; CHECK: @test6
; CHECK: zext <4 x i32> %arg to <4 x i64>
; CHECK: inttoptr <4 x i64> %1 to <4 x i8*>
%p1 = inttoptr <4 x i32> %arg to <4 x i8*>
ret <4 x i8*> %p1
}
define <4 x i8*> @test7(<4 x i128> %arg) nounwind {
; CHECK: @test7
; CHECK: trunc <4 x i128> %arg to <4 x i64>
; CHECK: inttoptr <4 x i64> %1 to <4 x i8*>
%p1 = inttoptr <4 x i128> %arg to <4 x i8*>
ret <4 x i8*> %p1
}