diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 6c5d386f029..062b9d9a933 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -511,6 +511,9 @@ SDValue DAGCombiner::CombineTo(SDNode *N, const SDValue *To, unsigned NumTo, DOUT << "\nReplacing.1 "; DEBUG(N->dump(&DAG)); DOUT << "\nWith: "; DEBUG(To[0].getNode()->dump(&DAG)); DOUT << " and " << NumTo-1 << " other values\n"; + DEBUG(for (unsigned i = 0, e = NumTo; i != e; ++i) + assert(N->getValueType(i) == To[i].getValueType() && + "Cannot combine value to value of different type!")); WorkListRemover DeadNodes(*this); DAG.ReplaceAllUsesWith(N, To, &DeadNodes); @@ -3310,7 +3313,7 @@ SDValue DAGCombiner::ReduceLoadWidth(SDNode *N) { ISD::LoadExtType ExtType = ISD::NON_EXTLOAD; SDValue N0 = N->getOperand(0); MVT VT = N->getValueType(0); - MVT EVT = N->getValueType(0); + MVT EVT = VT; // This transformation isn't valid for vector loads. if (VT.isVector()) @@ -3327,7 +3330,6 @@ SDValue DAGCombiner::ReduceLoadWidth(SDNode *N) { unsigned EVTBits = EVT.getSizeInBits(); unsigned ShAmt = 0; - bool CombineSRL = false; if (N0.getOpcode() == ISD::SRL && N0.hasOneUse()) { if (ConstantSDNode *N01 = dyn_cast(N0.getOperand(1))) { ShAmt = N01->getZExtValue(); @@ -3336,7 +3338,6 @@ SDValue DAGCombiner::ReduceLoadWidth(SDNode *N) { N0 = N0.getOperand(0); if (N0.getValueType().getSizeInBits() <= EVTBits) return SDValue(); - CombineSRL = true; } } } @@ -3368,22 +3369,12 @@ SDValue DAGCombiner::ReduceLoadWidth(SDNode *N) { : DAG.getExtLoad(ExtType, VT, LN0->getChain(), NewPtr, LN0->getSrcValue(), LN0->getSrcValueOffset() + PtrOff, EVT, LN0->isVolatile(), NewAlign); - AddToWorkList(Load.getNode()); - if (CombineSRL) { - WorkListRemover DeadNodes(*this); - DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1), - &DeadNodes); - CombineTo(N->getOperand(0).getNode(), Load); - } else - CombineTo(N0.getNode(), Load, Load.getValue(1)); - - if (ShAmt) { - if (Opc == ISD::SIGN_EXTEND_INREG) - return DAG.getNode(Opc, VT, Load, N->getOperand(1)); - else - return DAG.getNode(Opc, VT, Load); - } - return SDValue(N, 0); // Return N so it doesn't get rechecked! + // Replace the old load's chain with the new load's chain. + WorkListRemover DeadNodes(*this); + DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1), + &DeadNodes); + // Return the new loaded value. + return Load; } return SDValue(); diff --git a/test/CodeGen/X86/pr3317.ll b/test/CodeGen/X86/pr3317.ll new file mode 100644 index 00000000000..aa5ee7ce7c8 --- /dev/null +++ b/test/CodeGen/X86/pr3317.ll @@ -0,0 +1,46 @@ +; RUN: llvm-as < %s | llc -march=x86 +; PR3317 + + %ArraySInt16 = type { %JavaObject, i8*, [0 x i16] } + %ArraySInt8 = type { %JavaObject, i8*, [0 x i8] } + %Attribut = type { %ArraySInt16*, i32, i32 } + %CacheNode = type { i8*, %JavaCommonClass*, %CacheNode*, %Enveloppe* } + %Enveloppe = type { %CacheNode*, %ArraySInt16*, %ArraySInt16*, i8, %JavaClass*, %CacheNode } + %JavaArray = type { %JavaObject, i8* } + %JavaClass = type { %JavaCommonClass, i32, %VT*, [1 x %TaskClassMirror], i8*, %JavaField*, i16, %JavaField*, i16, %JavaMethod*, i16, %JavaMethod*, i16, i8*, %ArraySInt8*, i8*, %Attribut*, i16, %JavaClass**, i16, %JavaClass*, i16, i8, i32, i32, i8*, void (i8*)* } + %JavaCommonClass = type { %JavaCommonClass**, i32, [1 x %JavaObject*], i16, %JavaClass**, i16, %ArraySInt16*, %JavaClass*, i8* } + %JavaField = type { i8*, i16, %ArraySInt16*, %ArraySInt16*, %Attribut*, i16, %JavaClass*, i32, i16, i8* } + %JavaMethod = type { i8*, i16, %Attribut*, i16, %Enveloppe*, i16, %JavaClass*, %ArraySInt16*, %ArraySInt16*, i8, i8*, i32, i8* } + %JavaObject = type { %VT*, %JavaCommonClass*, i8* } + %TaskClassMirror = type { i32, i8* } + %UTF8 = type { %JavaObject, i8*, [0 x i16] } + %VT = type [0 x i32 (...)*] + +declare void @jnjvmNullPointerException() + +define i32 @JnJVM_java_rmi_activation_ActivationGroupID_hashCode__(%JavaObject* nocapture) nounwind { +start: + %1 = getelementptr %JavaObject* %0, i64 1, i32 1 ; <%JavaCommonClass**> [#uses=1] + %2 = load %JavaCommonClass** %1 ; <%JavaCommonClass*> [#uses=4] + %3 = icmp eq %JavaCommonClass* %2, null ; [#uses=1] + br i1 %3, label %verifyNullExit1, label %verifyNullCont2 + +verifyNullExit1: ; preds = %start + tail call void @jnjvmNullPointerException() + unreachable + +verifyNullCont2: ; preds = %start + %4 = bitcast %JavaCommonClass* %2 to { %JavaObject, i16, i32, i64 }* ; <{ %JavaObject, i16, i32, i64 }*> [#uses=1] + %5 = getelementptr { %JavaObject, i16, i32, i64 }* %4, i64 0, i32 2 ; [#uses=1] + %6 = load i32* %5 ; [#uses=1] + %7 = getelementptr %JavaCommonClass* %2, i64 0, i32 4 ; <%JavaClass***> [#uses=1] + %8 = bitcast %JavaClass*** %7 to i64* ; [#uses=1] + %9 = load i64* %8 ; [#uses=1] + %10 = trunc i64 %9 to i32 ; [#uses=1] + %11 = getelementptr %JavaCommonClass* %2, i64 0, i32 3 ; [#uses=1] + %12 = load i16* %11 ; [#uses=1] + %13 = sext i16 %12 to i32 ; [#uses=1] + %14 = xor i32 %10, %6 ; [#uses=1] + %15 = xor i32 %14, %13 ; [#uses=1] + ret i32 %15 +}