From 9fb25db11ef2d29bcfb413c0f896f55fe812979a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 1 May 2005 04:42:15 +0000 Subject: [PATCH] Implement getelementptr.ll:test11 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21647 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 6b958f2c77f..5fe95540de3 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2879,6 +2879,22 @@ Instruction *InstCombiner::visitSetCondInst(SetCondInst &I) { if (Constant *RHSC = dyn_cast(Op1)) { if (Instruction *LHSI = dyn_cast(Op0)) switch (LHSI->getOpcode()) { + case Instruction::GetElementPtr: + if (RHSC->isNullValue()) { + // Transform setcc GEP P, int 0, int 0, int 0, null -> setcc P, null + bool isAllZeros = true; + for (unsigned i = 1, e = LHSI->getNumOperands(); i != e; ++i) + if (!isa(LHSI->getOperand(i)) || + !cast(LHSI->getOperand(i))->isNullValue()) { + isAllZeros = false; + break; + } + if (isAllZeros) + return new SetCondInst(I.getOpcode(), LHSI->getOperand(0), + Constant::getNullValue(LHSI->getOperand(0)->getType())); + } + break; + case Instruction::PHI: if (Instruction *NV = FoldOpIntoPhi(I)) return NV;