diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-08-16 06:13:46 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-08-16 06:13:46 +0000 |
commit | 5c5df6283a3452aefccdf1b54600bd3b0aaa36a2 (patch) | |
tree | 38e3612823b424872d080092c1f0b262a904479b /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | 88c491ddec5bb8c5b087421f8f1f1239325beb45 (diff) | |
download | llvm-5c5df6283a3452aefccdf1b54600bd3b0aaa36a2.zip llvm-5c5df6283a3452aefccdf1b54600bd3b0aaa36a2.tar.gz llvm-5c5df6283a3452aefccdf1b54600bd3b0aaa36a2.tar.bz2 |
[InstSimplify] Fold gep (gep V, C), (xor V, -1) to C-1
llvm-svn: 278779
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 95273a78..3a1b272 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3645,7 +3645,6 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops, } } - // gep (gep V, C), (sub 0, V) -> C if (Q.DL.getTypeAllocSize(LastType) == 1 && all_of(Ops.slice(1).drop_back(1), [](Value *Idx) { return match(Idx, m_Zero()); })) { @@ -3657,11 +3656,18 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops, Ops[0]->stripAndAccumulateInBoundsConstantOffsets(Q.DL, BasePtrOffset); + // gep (gep V, C), (sub 0, V) -> C if (match(Ops.back(), m_Sub(m_Zero(), m_PtrToInt(m_Specific(StrippedBasePtr))))) { auto *CI = ConstantInt::get(GEPTy->getContext(), BasePtrOffset); return ConstantExpr::getIntToPtr(CI, GEPTy); } + // gep (gep V, C), (xor V, -1) -> C-1 + if (match(Ops.back(), + m_Xor(m_PtrToInt(m_Specific(StrippedBasePtr)), m_AllOnes()))) { + auto *CI = ConstantInt::get(GEPTy->getContext(), BasePtrOffset - 1); + return ConstantExpr::getIntToPtr(CI, GEPTy); + } } } |