summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-08-29 00:06:43 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-08-29 00:06:43 +0000
commit400e725bde52e5107e7394a3d5443ff6742e1325 (patch)
tree6c5b97119d029795100644f69857931f8f4c3471 /llvm/lib
parentb4f99dd07797e03e801b8cdfbbe0a3bdd391d6d5 (diff)
downloadbcm5719-llvm-400e725bde52e5107e7394a3d5443ff6742e1325.tar.gz
bcm5719-llvm-400e725bde52e5107e7394a3d5443ff6742e1325.zip
Revert two GEP-related InstCombine commits
This reverts commit r216523 and r216598; people have reported regressions. llvm-svn: 216698
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp51
1 files changed, 11 insertions, 40 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 2f80e8389d9..f01dca7fab8 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1508,48 +1508,19 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
GetElementPtrInst::Create(Src->getOperand(0), Indices, GEP.getName());
}
- if (DL && GEP.getNumIndices() == 1) {
+ // Canonicalize (gep i8* X, -(ptrtoint Y)) to (sub (ptrtoint X), (ptrtoint Y))
+ // The GEP pattern is emitted by the SCEV expander for certain kinds of
+ // pointer arithmetic.
+ if (DL && GEP.getNumIndices() == 1 &&
+ match(GEP.getOperand(1), m_Neg(m_PtrToInt(m_Value())))) {
unsigned AS = GEP.getPointerAddressSpace();
- if (GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
+ if (GEP.getType() == Builder->getInt8PtrTy(AS) &&
+ GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
DL->getPointerSizeInBits(AS)) {
- Type *PtrTy = GEP.getPointerOperandType();
- Type *Ty = PtrTy->getPointerElementType();
- uint64_t TyAllocSize = DL->getTypeAllocSize(Ty);
-
- uint64_t C;
- Value *V = nullptr;
- if (TyAllocSize == 1) {
- V = GEP.getOperand(1);
- } else if (match(GEP.getOperand(1),
- m_AShr(m_Value(V), m_ConstantInt(C)))) {
- if (TyAllocSize != 1ULL << C)
- V = nullptr;
- } else if (match(GEP.getOperand(1),
- m_SDiv(m_Value(V), m_ConstantInt(C)))) {
- if (TyAllocSize != C)
- V = nullptr;
- }
-
- if (V) {
- // Canonicalize (gep i8* X, -(ptrtoint Y))
- // to (inttoptr (sub (ptrtoint X), (ptrtoint Y)))
- // The GEP pattern is emitted by the SCEV expander for certain kinds of
- // pointer arithmetic.
- if (match(V, m_Neg(m_PtrToInt(m_Value())))) {
- Operator *Index = cast<Operator>(V);
- Value *PtrToInt = Builder->CreatePtrToInt(PtrOp, Index->getType());
- Value *NewSub = Builder->CreateSub(PtrToInt, Index->getOperand(1));
- return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
- }
- // Canonicalize (gep i8* X, (ptrtoint Y)-(ptrtoint X))
- // to (bitcast Y)
- Value *Y;
- if (match(V, m_Sub(m_PtrToInt(m_Value(Y)),
- m_PtrToInt(m_Specific(GEP.getOperand(0)))))) {
- return CastInst::CreatePointerBitCastOrAddrSpaceCast(Y,
- GEP.getType());
- }
- }
+ 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());
}
}
OpenPOWER on IntegriCloud