summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-03-06 22:32:40 +0000
committerSanjay Patel <spatel@rotateright.com>2017-03-06 22:32:40 +0000
commit7f18ec50bac7d9cc01016db3084435a2ab00e0f3 (patch)
tree82e84b23c1dcefcf5ea22e37fee2d087dad680fe /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parentf96e21ad6d84c49101f598d1eec8ff75a2ef15a5 (diff)
downloadbcm5719-llvm-7f18ec50bac7d9cc01016db3084435a2ab00e0f3.tar.gz
bcm5719-llvm-7f18ec50bac7d9cc01016db3084435a2ab00e0f3.zip
[DAG] refactor related div/rem folds; NFCI
This is known incomplete and not called in the right order relative to other folds, but that's the current behavior. I'm just trying to clean this up before making actual functional changes to make the patch smaller. The logic here should mimic the IR equivalents that are in InstSimplify's simplifyDivRem(). llvm-svn: 297086
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index b228f1e3cbb..1abc7049b1c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2368,6 +2368,31 @@ SDValue DAGCombiner::useDivRem(SDNode *Node) {
return combined;
}
+static SDValue simplifyDivRem(SDNode *N, SelectionDAG &DAG) {
+ SDValue N0 = N->getOperand(0);
+ SDValue N1 = N->getOperand(1);
+ EVT VT = N->getValueType(0);
+ SDLoc DL(N);
+
+ // X / undef -> undef
+ // X % undef -> undef
+ if (N1.isUndef())
+ return N1;
+
+ // X / 0 --> undef
+ // X % 0 --> undef
+ // We don't need to preserve faults!
+ if (isNullConstantOrNullSplatConstant(N1))
+ return DAG.getUNDEF(VT);
+
+ // undef / X -> 0
+ // undef % X -> 0
+ if (N0.isUndef())
+ return DAG.getConstant(0, DL, VT);
+
+ return SDValue();
+}
+
SDValue DAGCombiner::visitSDIV(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
@@ -2457,15 +2482,8 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
if (SDValue DivRem = useDivRem(N))
return DivRem;
- // undef / X -> 0
- if (N0.isUndef())
- return DAG.getConstant(0, DL, VT);
- // X / undef -> undef
- if (N1.isUndef())
- return N1;
- // X / 0 --> undef (we don't need to preserve faults!)
- if (N1C && N1C->isNullValue())
- return DAG.getUNDEF(VT);
+ if (SDValue V = simplifyDivRem(N, DAG))
+ return V;
return SDValue();
}
@@ -2535,15 +2553,8 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) {
if (SDValue DivRem = useDivRem(N))
return DivRem;
- // undef / X -> 0
- if (N0.isUndef())
- return DAG.getConstant(0, DL, VT);
- // X / undef -> undef
- if (N1.isUndef())
- return N1;
- // X / 0 --> undef (we don't need to preserve faults!)
- if (N1C && N1C->isNullValue())
- return DAG.getUNDEF(VT);
+ if (SDValue V = simplifyDivRem(N, DAG))
+ return V;
return SDValue();
}
@@ -2618,16 +2629,9 @@ SDValue DAGCombiner::visitREM(SDNode *N) {
if (SDValue DivRem = useDivRem(N))
return DivRem.getValue(1);
- // undef % X -> 0
- if (N0.isUndef())
- return DAG.getConstant(0, DL, VT);
- // X % undef -> undef
- if (N1.isUndef())
- return N1;
- // X % 0 --> undef (we don't need to preserve faults!)
- if (N1C && N1C->isNullValue())
- return DAG.getUNDEF(VT);
-
+ if (SDValue V = simplifyDivRem(N, DAG))
+ return V;
+
return SDValue();
}
OpenPOWER on IntegriCloud