[PATCH] D11345: ignore duplicate divisor uses when transforming into reciprocal multiplies (PR24141)
Sanjay Patel
spatel at rotateright.com
Mon Jul 20 14:08:27 PDT 2015
spatel updated this revision to Diff 30192.
spatel added a comment.
Patch updated:
I just discovered 'SmallPtrSet'.
Looks like it was designed exactly for this case, so let's use it here instead of a vector. Then, we don't have to use std::find() for dup checking.
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
@@ -8366,12 +8366,12 @@
if (N0CFP && N0CFP->isExactlyValue(1.0))
return SDValue();
- SmallVector<SDNode *, 4> Users;
+ // Only count unique users; duplicates may be present in the user list.
+ SmallPtrSet<SDNode*, 4> Users;
// Find all FDIV users of the same divisor.
- for (auto *U : N1->uses()) {
+ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11345.30192.patch
Type: text/x-patch
Size: 1635 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150720/d443745d/attachment.bin>
More information about the llvm-commits
mailing list