diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 52d620b1d54..3b29306bb54 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -8365,12 +8365,12 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) { if (N0CFP && N0CFP->isExactlyValue(1.0)) return SDValue(); - SmallVector Users; // Find all FDIV users of the same divisor. - for (auto *U : N1->uses()) { + // Use a set because duplicates may be present in the user list. + SetVector Users; + for (auto *U : N1->uses()) if (U->getOpcode() == ISD::FDIV && U->getOperand(1) == N1) - Users.push_back(U); - } + Users.insert(U); if (TLI.combineRepeatedFPDivisors(Users.size())) { SDValue FPOne = DAG.getConstantFP(1.0, DL, VT); diff --git a/test/CodeGen/X86/fdiv-combine.ll b/test/CodeGen/X86/fdiv-combine.ll index 34eac62e367..b65e9d01ab8 100644 --- a/test/CodeGen/X86/fdiv-combine.ll +++ b/test/CodeGen/X86/fdiv-combine.ll @@ -44,5 +44,24 @@ define double @div3_arcp(double %x, double %y, double %z) #0 { ret double %ret } +define void @PR24141() #0 { +; CHECK-LABEL: PR24141: +; CHECK: callq +; CHECK-NEXT: divsd +; CHECK-NEXT: jmp +entry: + br label %while.body + +while.body: + %x.0 = phi double [ undef, %entry ], [ %div, %while.body ] + %call = call { double, double } @g(double %x.0) + %xv0 = extractvalue { double, double } %call, 0 + %xv1 = extractvalue { double, double } %call, 1 + %div = fdiv double %xv0, %xv1 + br label %while.body +} + +declare { double, double } @g(double) + ; FIXME: If the backend understands 'arcp', then this attribute is unnecessary. attributes #0 = { "unsafe-fp-math"="true" }