aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-10-12 20:58:32 +0000
committerChris Lattner <sabre@nondot.org>2006-10-12 20:58:32 +0000
commit26d2990e03e60adc66fc5232baac5855fe65c747 (patch)
tree8506d36ec2b301c88e32085a15271582dda16203 /lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parent871a87de9a1563cbb95ce6d999d2229c61c55456 (diff)
Lower X%C into X/C+stuff. This allows the 'division by a constant' logic to
apply to rems as well as divs. This fixes PR945 and speeds up ReedSolomon from 14.57s to 10.90s (which is now faster than gcc). It compiles CodeGen/X86/rem.ll into: _test1: subl $4, %esp movl %esi, (%esp) movl $2155905153, %ecx movl 8(%esp), %esi movl %esi, %eax imull %ecx addl %esi, %edx movl %edx, %eax shrl $31, %eax sarl $7, %edx addl %eax, %edx imull $255, %edx, %eax subl %eax, %esi movl %esi, %eax movl (%esp), %esi addl $4, %esp ret _test2: movl 4(%esp), %eax movl %eax, %ecx sarl $31, %ecx shrl $24, %ecx addl %eax, %ecx andl $4294967040, %ecx subl %ecx, %eax ret _test3: subl $4, %esp movl %esi, (%esp) movl $2155905153, %ecx movl 8(%esp), %esi movl %esi, %eax mull %ecx shrl $7, %edx imull $255, %edx, %eax subl %eax, %esi movl %esi, %eax movl (%esp), %esi addl $4, %esp ret instead of div/idiv instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/DAGCombiner.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 70ff8371f7..d6379dc858 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -885,6 +885,18 @@ SDOperand DAGCombiner::visitSREM(SDNode *N) {
if (TLI.MaskedValueIsZero(N1, SignBit) &&
TLI.MaskedValueIsZero(N0, SignBit))
return DAG.getNode(ISD::UREM, VT, N0, N1);
+
+ // Unconditionally lower X%C -> X-X/C*C. This allows the X/C logic to hack on
+ // the remainder operation.
+ if (N1C && !N1C->isNullValue()) {
+ SDOperand Div = DAG.getNode(ISD::SDIV, VT, N0, N1);
+ SDOperand Mul = DAG.getNode(ISD::MUL, VT, Div, N1);
+ SDOperand Sub = DAG.getNode(ISD::SUB, VT, N0, Mul);
+ AddToWorkList(Div.Val);
+ AddToWorkList(Mul.Val);
+ return Sub;
+ }
+
return SDOperand();
}
@@ -911,6 +923,18 @@ SDOperand DAGCombiner::visitUREM(SDNode *N) {
}
}
}
+
+ // Unconditionally lower X%C -> X-X/C*C. This allows the X/C logic to hack on
+ // the remainder operation.
+ if (N1C && !N1C->isNullValue()) {
+ SDOperand Div = DAG.getNode(ISD::UDIV, VT, N0, N1);
+ SDOperand Mul = DAG.getNode(ISD::MUL, VT, Div, N1);
+ SDOperand Sub = DAG.getNode(ISD::SUB, VT, N0, Mul);
+ AddToWorkList(Div.Val);
+ AddToWorkList(Mul.Val);
+ return Sub;
+ }
+
return SDOperand();
}