mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-12 14:41:05 +00:00
Instcombine cast (getelementptr Ptr, 0, 0, 0) to ... into: cast Ptr to ...
This fixes type safety problems in a variety of benchmarks that were confusing DSA. llvm-svn: 6837
This commit is contained in:
parent
b772ce2a37
commit
9a0da3e531
@ -930,6 +930,23 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
|
||||
}
|
||||
}
|
||||
|
||||
// If casting the result of a getelementptr instruction with no offset, turn
|
||||
// this into a cast of the original pointer!
|
||||
//
|
||||
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CI.getOperand(0))) {
|
||||
bool AllZeroOperands = true;
|
||||
for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
|
||||
if (!isa<Constant>(GEP->getOperand(i)) ||
|
||||
!cast<Constant>(GEP->getOperand(i))->isNullValue()) {
|
||||
AllZeroOperands = false;
|
||||
break;
|
||||
}
|
||||
if (AllZeroOperands) {
|
||||
CI.setOperand(0, GEP->getOperand(0));
|
||||
return &CI;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user