[PATCH] D11345: ignore duplicate divisor uses when transforming into reciprocal multiplies (PR24141)

Sanjay Patel spatel at rotateright.com
Sun Jul 19 16:54:52 PDT 2015


spatel created this revision.
spatel added reviewers: hfinkel, majnemer, rtrieu, nlewycky.
spatel added a subscriber: llvm-commits.

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 combineRepeatedFPDivisors() check entirely because there really is only one user of the divisor.

http://reviews.llvm.org/D11345

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  test/CodeGen/X86/fdiv-combine.ll

Index: test/CodeGen/X86/fdiv-combine.ll
===================================================================
--- test/CodeGen/X86/fdiv-combine.ll
+++ test/CodeGen/X86/fdiv-combine.ll
@@ -44,5 +44,24 @@
   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" }
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -8369,8 +8369,11 @@
     SmallVector<SDNode *, 4> Users;
     // Find all FDIV users of the same divisor.
     for (auto *U : N1->uses()) {
-      if (U->getOpcode() == ISD::FDIV && U->getOperand(1) == N1)
-        Users.push_back(U);
+      if (U->getOpcode() == ISD::FDIV && U->getOperand(1) == N1) {
+        // Only count unique users; duplicates may be present in the list.
+        if (std::find(Users.begin(), Users.end(), U) == Users.end())
+          Users.push_back(U);
+      }
     }
 
     if (TLI.combineRepeatedFPDivisors(Users.size())) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11345.30129.patch
Type: text/x-patch
Size: 1589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150719/b6efecb7/attachment.bin>


More information about the llvm-commits mailing list