From 54a96a2ad66837a1b1857daf1a90a1573a8e0a6e Mon Sep 17 00:00:00 2001 From: Alkis Evlogimenos Date: Wed, 8 Dec 2004 23:10:30 +0000 Subject: [PATCH] Fix this regression and remove the XFAIL from this test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18674 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 8 +++++--- .../Transforms/InstCombine/2004-12-08-InstCombineCrash.ll | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9eb30549f47..356b86fdbb0 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4216,9 +4216,11 @@ bool InstCombiner::runOnFunction(Function &F) { // Instruction isn't dead, see if we can constant propagate it... if (Constant *C = ConstantFoldInstruction(I)) { + Value* Ptr = I->getOperand(0); if (isa(I) && - cast(I->getOperand(0))->isNullValue() && - !isa(C)) { + cast(Ptr)->isNullValue() && + !isa(C) && + cast(Ptr->getType())->getElementType()->isSized()) { // If this is a constant expr gep that is effectively computing an // "offsetof", fold it into 'cast int X to T*' instead of 'gep 0, 0, 12' bool isFoldableGEP = true; @@ -4226,7 +4228,7 @@ bool InstCombiner::runOnFunction(Function &F) { if (!isa(I->getOperand(i))) isFoldableGEP = false; if (isFoldableGEP) { - uint64_t Offset = TD->getIndexedOffset(I->getOperand(0)->getType(), + uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), std::vector(I->op_begin()+1, I->op_end())); C = ConstantUInt::get(Type::ULongTy, Offset); C = ConstantExpr::getCast(C, TD->getIntPtrType()); diff --git a/test/Transforms/InstCombine/2004-12-08-InstCombineCrash.ll b/test/Transforms/InstCombine/2004-12-08-InstCombineCrash.ll index 15b75bd983a..02939c0c3ee 100644 --- a/test/Transforms/InstCombine/2004-12-08-InstCombineCrash.ll +++ b/test/Transforms/InstCombine/2004-12-08-InstCombineCrash.ll @@ -1,5 +1,4 @@ ; RUN: llvm-as %s -o - | opt -instcombine -; XFAIL: * %struct.llvm_java_object_base = type opaque "java/lang/Object" = type { %struct.llvm_java_object_base } -- 2.34.1