mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 07:32:52 +00:00
LangRef.html says that inttoptr and ptrtoint always use zero-extension
when the cast is extending. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95046 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6acb86dcfa
commit
3b5487e627
@ -1145,16 +1145,22 @@ Instruction *InstCombiner::visitSIToFP(CastInst &CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) {
|
Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) {
|
||||||
// If the source integer type is larger than the intptr_t type for
|
// If the source integer type is not the intptr_t type for this target, do a
|
||||||
// this target, do a trunc to the intptr_t type, then inttoptr of it. This
|
// trunc or zext to the intptr_t type, then inttoptr of it. This allows the
|
||||||
// allows the trunc to be exposed to other transforms. Don't do this for
|
// cast to be exposed to other transforms.
|
||||||
// extending inttoptr's, because we don't know if the target sign or zero
|
if (TD) {
|
||||||
// extends to pointers.
|
if (CI.getOperand(0)->getType()->getScalarSizeInBits() >
|
||||||
if (TD && CI.getOperand(0)->getType()->getScalarSizeInBits() >
|
TD->getPointerSizeInBits()) {
|
||||||
TD->getPointerSizeInBits()) {
|
Value *P = Builder->CreateTrunc(CI.getOperand(0),
|
||||||
Value *P = Builder->CreateTrunc(CI.getOperand(0),
|
TD->getIntPtrType(CI.getContext()), "tmp");
|
||||||
TD->getIntPtrType(CI.getContext()), "tmp");
|
return new IntToPtrInst(P, CI.getType());
|
||||||
return new IntToPtrInst(P, CI.getType());
|
}
|
||||||
|
if (CI.getOperand(0)->getType()->getScalarSizeInBits() <
|
||||||
|
TD->getPointerSizeInBits()) {
|
||||||
|
Value *P = Builder->CreateZExt(CI.getOperand(0),
|
||||||
|
TD->getIntPtrType(CI.getContext()), "tmp");
|
||||||
|
return new IntToPtrInst(P, CI.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Instruction *I = commonCastTransforms(CI))
|
if (Instruction *I = commonCastTransforms(CI))
|
||||||
@ -1216,17 +1222,22 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitPtrToInt(PtrToIntInst &CI) {
|
Instruction *InstCombiner::visitPtrToInt(PtrToIntInst &CI) {
|
||||||
// If the destination integer type is smaller than the intptr_t type for
|
// If the destination integer type is not the intptr_t type for this target,
|
||||||
// this target, do a ptrtoint to intptr_t then do a trunc. This allows the
|
// do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
|
||||||
// trunc to be exposed to other transforms. Don't do this for extending
|
// to be exposed to other transforms.
|
||||||
// ptrtoint's, because we don't know if the target sign or zero extends its
|
if (TD) {
|
||||||
// pointers.
|
if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
|
||||||
if (TD &&
|
Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
|
||||||
CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
|
TD->getIntPtrType(CI.getContext()),
|
||||||
Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
|
"tmp");
|
||||||
TD->getIntPtrType(CI.getContext()),
|
return new TruncInst(P, CI.getType());
|
||||||
"tmp");
|
}
|
||||||
return new TruncInst(P, CI.getType());
|
if (CI.getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) {
|
||||||
|
Value *P = Builder->CreatePtrToInt(CI.getOperand(0),
|
||||||
|
TD->getIntPtrType(CI.getContext()),
|
||||||
|
"tmp");
|
||||||
|
return new ZExtInst(P, CI.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return commonPointerCastTransforms(CI);
|
return commonPointerCastTransforms(CI);
|
||||||
|
Loading…
Reference in New Issue
Block a user