Commit 2b53f11c authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r243500: (conflicts resolved manually since the branch doesn't have r243293)

------------------------------------------------------------------------
r243500 | spatel | 2015-07-28 16:28:22 -0700 (Tue, 28 Jul 2015) | 16 lines

ignore duplicate divisor uses when transforming into reciprocal multiplies (PR24141)

PR24141: https://llvm.org/bugs/show_bug.cgi?id=24141
contains a test case where we have duplicate entries in a node's uses() list.

After r241826, we use CombineTo() to delete dead nodes when combining the uses into
reciprocal multiplies, but this fails if we encounter the just-deleted node again in
the list.

The solution in this patch is to not add duplicate entries to the list of users that
we will subsequently iterate over. For the test case, this avoids triggering the
combine divisors logic entirely because there really is only one user of the divisor.

Differential Revision: http://reviews.llvm.org/D11345
------------------------------------------------------------------------

llvm-svn: 243524
parent 08ae2b71
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -8365,12 +8365,12 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
    if (N0CFP && N0CFP->isExactlyValue(1.0))
      return SDValue();
    SmallVector<SDNode *, 4> 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<SDNode *> 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);
+19 −0
Original line number Diff line number Diff line
@@ -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" }