blob: ddbe45a0a37c567f4008ef7e362ca365d87cf844 [file] [log] [blame]
Nate Begeman4ebd8052005-09-01 23:24:04 +00001//===-- DAGCombiner.cpp - Implement a DAG node combiner -------------------===//
Nate Begeman1d4d4142005-09-01 00:19:25 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Nate Begeman and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass combines dag nodes to form fewer, simpler DAG nodes. It can be run
11// both before and after the DAG is legalized.
12//
13// FIXME: Missing folds
14// sdiv, udiv, srem, urem (X, const) where X is an integer can be expanded into
15// a sequence of multiplies, shifts, and adds. This should be controlled by
16// some kind of hint from the target that int div is expensive.
17// various folds of mulh[s,u] by constants such as -1, powers of 2, etc.
18//
19// FIXME: Should add a corresponding version of fold AND with
20// ZERO_EXTEND/SIGN_EXTEND by converting them to an ANY_EXTEND node which
21// we don't have yet.
22//
23// FIXME: mul (x, const) -> shifts + adds
Nate Begeman1d4d4142005-09-01 00:19:25 +000024// FIXME: undef values
Nate Begeman1d4d4142005-09-01 00:19:25 +000025// FIXME: zero extend when top bits are 0 -> drop it ?
Nate Begeman4ebd8052005-09-01 23:24:04 +000026// FIXME: make truncate see through SIGN_EXTEND and AND
27// FIXME: sext_in_reg(setcc) on targets that return zero or one, and where
28// EVT != MVT::i1 can drop the sext.
Nate Begeman4ebd8052005-09-01 23:24:04 +000029// FIXME: (sra (sra x, c1), c2) -> (sra x, c1+c2)
Nate Begeman646d7e22005-09-02 21:18:40 +000030// FIXME: verify that getNode can't return extends with an operand whose type
31// is >= to that of the extend.
32// FIXME: divide by zero is currently left unfolded. do we want to turn this
33// into an undef?
Nate Begeman1d4d4142005-09-01 00:19:25 +000034//
35//===----------------------------------------------------------------------===//
36
37#define DEBUG_TYPE "dagcombine"
38#include "llvm/ADT/Statistic.h"
39#include "llvm/CodeGen/SelectionDAG.h"
Nate Begeman2300f552005-09-07 00:15:36 +000040#include "llvm/Support/Debug.h"
Nate Begeman1d4d4142005-09-01 00:19:25 +000041#include "llvm/Support/MathExtras.h"
42#include "llvm/Target/TargetLowering.h"
Chris Lattnera500fc62005-09-09 23:53:39 +000043#include <algorithm>
Nate Begeman1d4d4142005-09-01 00:19:25 +000044#include <cmath>
45using namespace llvm;
46
47namespace {
48 Statistic<> NodesCombined ("dagcombiner", "Number of dag nodes combined");
49
50 class DAGCombiner {
51 SelectionDAG &DAG;
52 TargetLowering &TLI;
Nate Begeman4ebd8052005-09-01 23:24:04 +000053 bool AfterLegalize;
Nate Begeman1d4d4142005-09-01 00:19:25 +000054
55 // Worklist of all of the nodes that need to be simplified.
56 std::vector<SDNode*> WorkList;
57
58 /// AddUsersToWorkList - When an instruction is simplified, add all users of
59 /// the instruction to the work lists because they might get more simplified
60 /// now.
61 ///
62 void AddUsersToWorkList(SDNode *N) {
63 for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end();
Nate Begeman4ebd8052005-09-01 23:24:04 +000064 UI != UE; ++UI)
65 WorkList.push_back(*UI);
Nate Begeman1d4d4142005-09-01 00:19:25 +000066 }
67
68 /// removeFromWorkList - remove all instances of N from the worklist.
69 void removeFromWorkList(SDNode *N) {
70 WorkList.erase(std::remove(WorkList.begin(), WorkList.end(), N),
71 WorkList.end());
72 }
73
74 /// visit - call the node-specific routine that knows how to fold each
75 /// particular type of node.
Nate Begeman83e75ec2005-09-06 04:43:02 +000076 SDOperand visit(SDNode *N);
Nate Begeman1d4d4142005-09-01 00:19:25 +000077
78 // Visitation implementation - Implement dag node combining for different
79 // node types. The semantics are as follows:
80 // Return Value:
Nate Begeman2300f552005-09-07 00:15:36 +000081 // SDOperand.Val == 0 - No change was made
82 // otherwise - N should be replaced by the returned Operand.
Nate Begeman1d4d4142005-09-01 00:19:25 +000083 //
Nate Begeman83e75ec2005-09-06 04:43:02 +000084 SDOperand visitTokenFactor(SDNode *N);
85 SDOperand visitADD(SDNode *N);
86 SDOperand visitSUB(SDNode *N);
87 SDOperand visitMUL(SDNode *N);
88 SDOperand visitSDIV(SDNode *N);
89 SDOperand visitUDIV(SDNode *N);
90 SDOperand visitSREM(SDNode *N);
91 SDOperand visitUREM(SDNode *N);
92 SDOperand visitMULHU(SDNode *N);
93 SDOperand visitMULHS(SDNode *N);
94 SDOperand visitAND(SDNode *N);
95 SDOperand visitOR(SDNode *N);
96 SDOperand visitXOR(SDNode *N);
97 SDOperand visitSHL(SDNode *N);
98 SDOperand visitSRA(SDNode *N);
99 SDOperand visitSRL(SDNode *N);
100 SDOperand visitCTLZ(SDNode *N);
101 SDOperand visitCTTZ(SDNode *N);
102 SDOperand visitCTPOP(SDNode *N);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000103 // select
104 // select_cc
105 // setcc
Nate Begeman83e75ec2005-09-06 04:43:02 +0000106 SDOperand visitSIGN_EXTEND(SDNode *N);
107 SDOperand visitZERO_EXTEND(SDNode *N);
108 SDOperand visitSIGN_EXTEND_INREG(SDNode *N);
109 SDOperand visitTRUNCATE(SDNode *N);
110 SDOperand visitSINT_TO_FP(SDNode *N);
111 SDOperand visitUINT_TO_FP(SDNode *N);
112 SDOperand visitFP_TO_SINT(SDNode *N);
113 SDOperand visitFP_TO_UINT(SDNode *N);
114 SDOperand visitFP_ROUND(SDNode *N);
115 SDOperand visitFP_ROUND_INREG(SDNode *N);
116 SDOperand visitFP_EXTEND(SDNode *N);
117 SDOperand visitFNEG(SDNode *N);
118 SDOperand visitFABS(SDNode *N);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000119 // brcond
120 // brcondtwoway
121 // br_cc
122 // brtwoway_cc
123public:
124 DAGCombiner(SelectionDAG &D)
Nate Begeman646d7e22005-09-02 21:18:40 +0000125 : DAG(D), TLI(D.getTargetLoweringInfo()), AfterLegalize(false) {}
Nate Begeman1d4d4142005-09-01 00:19:25 +0000126
127 /// Run - runs the dag combiner on all nodes in the work list
Nate Begeman4ebd8052005-09-01 23:24:04 +0000128 void Run(bool RunningAfterLegalize);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000129 };
130}
131
132/// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use
133/// this predicate to simplify operations downstream. V and Mask are known to
134/// be the same type.
135static bool MaskedValueIsZero(const SDOperand &Op, uint64_t Mask,
136 const TargetLowering &TLI) {
137 unsigned SrcBits;
138 if (Mask == 0) return true;
139
140 // If we know the result of a setcc has the top bits zero, use this info.
141 switch (Op.getOpcode()) {
Nate Begeman4ebd8052005-09-01 23:24:04 +0000142 case ISD::Constant:
143 return (cast<ConstantSDNode>(Op)->getValue() & Mask) == 0;
144 case ISD::SETCC:
Nate Begeman646d7e22005-09-02 21:18:40 +0000145 // FIXME: teach this about non ZeroOrOne values, such as 0 or -1
Nate Begeman4ebd8052005-09-01 23:24:04 +0000146 return ((Mask & 1) == 0) &&
147 TLI.getSetCCResultContents() == TargetLowering::ZeroOrOneSetCCResult;
148 case ISD::ZEXTLOAD:
149 SrcBits = MVT::getSizeInBits(cast<VTSDNode>(Op.getOperand(3))->getVT());
150 return (Mask & ((1ULL << SrcBits)-1)) == 0; // Returning only the zext bits.
151 case ISD::ZERO_EXTEND:
152 SrcBits = MVT::getSizeInBits(Op.getOperand(0).getValueType());
153 return MaskedValueIsZero(Op.getOperand(0),Mask & ((1ULL << SrcBits)-1),TLI);
154 case ISD::AssertZext:
155 SrcBits = MVT::getSizeInBits(cast<VTSDNode>(Op.getOperand(1))->getVT());
156 return (Mask & ((1ULL << SrcBits)-1)) == 0; // Returning only the zext bits.
157 case ISD::AND:
158 // (X & C1) & C2 == 0 iff C1 & C2 == 0.
159 if (ConstantSDNode *AndRHS = dyn_cast<ConstantSDNode>(Op.getOperand(1)))
160 return MaskedValueIsZero(Op.getOperand(0),AndRHS->getValue() & Mask, TLI);
161 // FALL THROUGH
162 case ISD::OR:
163 case ISD::XOR:
164 return MaskedValueIsZero(Op.getOperand(0), Mask, TLI) &&
165 MaskedValueIsZero(Op.getOperand(1), Mask, TLI);
166 case ISD::SELECT:
167 return MaskedValueIsZero(Op.getOperand(1), Mask, TLI) &&
168 MaskedValueIsZero(Op.getOperand(2), Mask, TLI);
169 case ISD::SELECT_CC:
170 return MaskedValueIsZero(Op.getOperand(2), Mask, TLI) &&
171 MaskedValueIsZero(Op.getOperand(3), Mask, TLI);
172 case ISD::SRL:
173 // (ushr X, C1) & C2 == 0 iff X & (C2 << C1) == 0
174 if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
175 uint64_t NewVal = Mask << ShAmt->getValue();
176 SrcBits = MVT::getSizeInBits(Op.getValueType());
177 if (SrcBits != 64) NewVal &= (1ULL << SrcBits)-1;
178 return MaskedValueIsZero(Op.getOperand(0), NewVal, TLI);
179 }
180 return false;
181 case ISD::SHL:
182 // (ushl X, C1) & C2 == 0 iff X & (C2 >> C1) == 0
183 if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
184 uint64_t NewVal = Mask >> ShAmt->getValue();
185 return MaskedValueIsZero(Op.getOperand(0), NewVal, TLI);
186 }
187 return false;
188 case ISD::CTTZ:
189 case ISD::CTLZ:
190 case ISD::CTPOP:
191 // Bit counting instructions can not set the high bits of the result
192 // register. The max number of bits sets depends on the input.
193 return (Mask & (MVT::getSizeInBits(Op.getValueType())*2-1)) == 0;
194
195 // TODO we could handle some SRA cases here.
196 default: break;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000197 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000198 return false;
199}
200
Nate Begeman4ebd8052005-09-01 23:24:04 +0000201// isSetCCEquivalent - Return true if this node is a setcc, or is a select_cc
202// that selects between the values 1 and 0, making it equivalent to a setcc.
Nate Begeman646d7e22005-09-02 21:18:40 +0000203// Also, set the incoming LHS, RHS, and CC references to the appropriate
204// nodes based on the type of node we are checking. This simplifies life a
205// bit for the callers.
206static bool isSetCCEquivalent(SDOperand N, SDOperand &LHS, SDOperand &RHS,
207 SDOperand &CC) {
208 if (N.getOpcode() == ISD::SETCC) {
209 LHS = N.getOperand(0);
210 RHS = N.getOperand(1);
211 CC = N.getOperand(2);
Nate Begeman4ebd8052005-09-01 23:24:04 +0000212 return true;
Nate Begeman646d7e22005-09-02 21:18:40 +0000213 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000214 if (N.getOpcode() == ISD::SELECT_CC &&
215 N.getOperand(2).getOpcode() == ISD::Constant &&
216 N.getOperand(3).getOpcode() == ISD::Constant &&
217 cast<ConstantSDNode>(N.getOperand(2))->getValue() == 1 &&
Nate Begeman646d7e22005-09-02 21:18:40 +0000218 cast<ConstantSDNode>(N.getOperand(3))->isNullValue()) {
219 LHS = N.getOperand(0);
220 RHS = N.getOperand(1);
221 CC = N.getOperand(4);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000222 return true;
Nate Begeman646d7e22005-09-02 21:18:40 +0000223 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000224 return false;
225}
226
Nate Begeman99801192005-09-07 23:25:52 +0000227// isOneUseSetCC - Return true if this is a SetCC-equivalent operation with only
228// one use. If this is true, it allows the users to invert the operation for
229// free when it is profitable to do so.
230static bool isOneUseSetCC(SDOperand N) {
Nate Begeman646d7e22005-09-02 21:18:40 +0000231 SDOperand N0, N1, N2;
Nate Begeman646d7e22005-09-02 21:18:40 +0000232 if (isSetCCEquivalent(N, N0, N1, N2) && N.Val->hasOneUse())
Nate Begeman4ebd8052005-09-01 23:24:04 +0000233 return true;
234 return false;
235}
236
237void DAGCombiner::Run(bool RunningAfterLegalize) {
238 // set the instance variable, so that the various visit routines may use it.
239 AfterLegalize = RunningAfterLegalize;
240
Nate Begeman646d7e22005-09-02 21:18:40 +0000241 // Add all the dag nodes to the worklist.
242 WorkList.insert(WorkList.end(), DAG.allnodes_begin(), DAG.allnodes_end());
Nate Begeman83e75ec2005-09-06 04:43:02 +0000243
Nate Begeman1d4d4142005-09-01 00:19:25 +0000244 // while the worklist isn't empty, inspect the node on the end of it and
245 // try and combine it.
246 while (!WorkList.empty()) {
247 SDNode *N = WorkList.back();
248 WorkList.pop_back();
249
250 // If N has no uses, it is dead. Make sure to revisit all N's operands once
251 // N is deleted from the DAG, since they too may now be dead.
Nate Begeman83e75ec2005-09-06 04:43:02 +0000252 // FIXME: is there a better way to keep from deleting the dag root because
253 // we think it has no uses? This works for now...
254 if (N->use_empty() && N != DAG.getRoot().Val) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000255 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
256 WorkList.push_back(N->getOperand(i).Val);
257
258 DAG.DeleteNode(N);
259 removeFromWorkList(N);
260 continue;
261 }
262
Nate Begeman83e75ec2005-09-06 04:43:02 +0000263 SDOperand RV = visit(N);
264 if (RV.Val) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000265 ++NodesCombined;
Nate Begeman646d7e22005-09-02 21:18:40 +0000266 // If we get back the same node we passed in, rather than a new node or
267 // zero, we know that the node must have defined multiple values and
268 // CombineTo was used. Since CombineTo takes care of the worklist
269 // mechanics for us, we have no work to do in this case.
Nate Begeman83e75ec2005-09-06 04:43:02 +0000270 if (RV.Val != N) {
Nate Begeman2300f552005-09-07 00:15:36 +0000271 DEBUG(std::cerr << "\nReplacing "; N->dump();
272 std::cerr << "\nWith: "; RV.Val->dump();
273 std::cerr << '\n');
Nate Begeman99801192005-09-07 23:25:52 +0000274 DAG.ReplaceAllUsesWith(N, std::vector<SDOperand>(1, RV));
Nate Begeman646d7e22005-09-02 21:18:40 +0000275
276 // Push the new node and any users onto the worklist
Nate Begeman83e75ec2005-09-06 04:43:02 +0000277 WorkList.push_back(RV.Val);
278 AddUsersToWorkList(RV.Val);
Nate Begeman646d7e22005-09-02 21:18:40 +0000279
280 // Nodes can end up on the worklist more than once. Make sure we do
281 // not process a node that has been replaced.
282 removeFromWorkList(N);
283 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000284 }
285 }
286}
287
Nate Begeman83e75ec2005-09-06 04:43:02 +0000288SDOperand DAGCombiner::visit(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000289 switch(N->getOpcode()) {
290 default: break;
Nate Begeman4942a962005-09-01 00:33:32 +0000291 case ISD::TokenFactor: return visitTokenFactor(N);
Nate Begeman646d7e22005-09-02 21:18:40 +0000292 case ISD::ADD: return visitADD(N);
293 case ISD::SUB: return visitSUB(N);
294 case ISD::MUL: return visitMUL(N);
295 case ISD::SDIV: return visitSDIV(N);
296 case ISD::UDIV: return visitUDIV(N);
297 case ISD::SREM: return visitSREM(N);
298 case ISD::UREM: return visitUREM(N);
299 case ISD::MULHU: return visitMULHU(N);
300 case ISD::MULHS: return visitMULHS(N);
301 case ISD::AND: return visitAND(N);
302 case ISD::OR: return visitOR(N);
303 case ISD::XOR: return visitXOR(N);
304 case ISD::SHL: return visitSHL(N);
305 case ISD::SRA: return visitSRA(N);
306 case ISD::SRL: return visitSRL(N);
307 case ISD::CTLZ: return visitCTLZ(N);
308 case ISD::CTTZ: return visitCTTZ(N);
309 case ISD::CTPOP: return visitCTPOP(N);
310 case ISD::SIGN_EXTEND: return visitSIGN_EXTEND(N);
311 case ISD::ZERO_EXTEND: return visitZERO_EXTEND(N);
312 case ISD::SIGN_EXTEND_INREG: return visitSIGN_EXTEND_INREG(N);
313 case ISD::TRUNCATE: return visitTRUNCATE(N);
314 case ISD::SINT_TO_FP: return visitSINT_TO_FP(N);
315 case ISD::UINT_TO_FP: return visitUINT_TO_FP(N);
316 case ISD::FP_TO_SINT: return visitFP_TO_SINT(N);
317 case ISD::FP_TO_UINT: return visitFP_TO_UINT(N);
318 case ISD::FP_ROUND: return visitFP_ROUND(N);
319 case ISD::FP_ROUND_INREG: return visitFP_ROUND_INREG(N);
320 case ISD::FP_EXTEND: return visitFP_EXTEND(N);
321 case ISD::FNEG: return visitFNEG(N);
322 case ISD::FABS: return visitFABS(N);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000323 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000324 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000325}
326
Nate Begeman83e75ec2005-09-06 04:43:02 +0000327SDOperand DAGCombiner::visitTokenFactor(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000328 // If the token factor has two operands and one is the entry token, replace
329 // the token factor with the other operand.
330 if (N->getNumOperands() == 2) {
331 if (N->getOperand(0).getOpcode() == ISD::EntryToken)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000332 return N->getOperand(1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000333 if (N->getOperand(1).getOpcode() == ISD::EntryToken)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000334 return N->getOperand(0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000335 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000336 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000337}
338
Nate Begeman83e75ec2005-09-06 04:43:02 +0000339SDOperand DAGCombiner::visitADD(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000340 SDOperand N0 = N->getOperand(0);
341 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000342 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
343 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
344 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
345 ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
Nate Begemanf89d78d2005-09-07 16:09:19 +0000346 MVT::ValueType VT = N0.getValueType();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000347
348 // fold (add c1, c2) -> c1+c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000349 if (N0C && N1C)
Nate Begemanf89d78d2005-09-07 16:09:19 +0000350 return DAG.getConstant(N0C->getValue() + N1C->getValue(), VT);
Nate Begeman99801192005-09-07 23:25:52 +0000351 // canonicalize constant to RHS
352 if (N0C && !N1C) {
353 std::swap(N0, N1);
354 std::swap(N0C, N1C);
355 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000356 // fold (add x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000357 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000358 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000359 // fold floating point (add c1, c2) -> c1+c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000360 if (N0CFP && N1CFP)
Nate Begemanf89d78d2005-09-07 16:09:19 +0000361 return DAG.getConstantFP(N0CFP->getValue() + N1CFP->getValue(), VT);
Nate Begeman223df222005-09-08 20:18:10 +0000362 // fold (add (add x, c1), c2) -> (add x, c1+c2)
363 if (N1C && N0.getOpcode() == ISD::ADD) {
364 ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand(0));
365 ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
366 if (N00C)
367 return DAG.getNode(ISD::ADD, VT, N0.getOperand(1),
368 DAG.getConstant(N1C->getValue()+N00C->getValue(), VT));
369 if (N01C)
370 return DAG.getNode(ISD::ADD, VT, N0.getOperand(0),
371 DAG.getConstant(N1C->getValue()+N01C->getValue(), VT));
372 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000373 // fold (A + (-B)) -> A-B
374 if (N1.getOpcode() == ISD::FNEG)
Nate Begemanf89d78d2005-09-07 16:09:19 +0000375 return DAG.getNode(ISD::SUB, VT, N0, N1.getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000376 // fold ((-A) + B) -> B-A
377 if (N0.getOpcode() == ISD::FNEG)
Nate Begemanf89d78d2005-09-07 16:09:19 +0000378 return DAG.getNode(ISD::SUB, VT, N1, N0.getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000379 // fold ((0-A) + B) -> B-A
380 if (N0.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N0.getOperand(0)) &&
381 cast<ConstantSDNode>(N0.getOperand(0))->isNullValue())
Nate Begemanf89d78d2005-09-07 16:09:19 +0000382 return DAG.getNode(ISD::SUB, VT, N1, N0.getOperand(1));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000383 // fold (A + (0-B)) -> A-B
384 if (N1.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N1.getOperand(0)) &&
385 cast<ConstantSDNode>(N1.getOperand(0))->isNullValue())
Nate Begemanf89d78d2005-09-07 16:09:19 +0000386 return DAG.getNode(ISD::SUB, VT, N0, N1.getOperand(1));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000387 // fold (A+(B-A)) -> B for non-fp types
388 if (N1.getOpcode() == ISD::SUB && N0 == N1.getOperand(1) &&
389 !MVT::isFloatingPoint(N1.getValueType()))
Nate Begeman83e75ec2005-09-06 04:43:02 +0000390 return N1.getOperand(0);
391 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000392}
393
Nate Begeman83e75ec2005-09-06 04:43:02 +0000394SDOperand DAGCombiner::visitSUB(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000395 SDOperand N0 = N->getOperand(0);
396 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000397 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val);
398 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
399 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0.Val);
400 ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1.Val);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000401
402 // fold (sub c1, c2) -> c1-c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000403 if (N0C && N1C)
404 return DAG.getConstant(N0C->getValue() - N1C->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000405 N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000406 // fold (sub x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000407 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000408 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000409 // fold floating point (sub c1, c2) -> c1-c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000410 if (N0CFP && N1CFP)
411 return DAG.getConstantFP(N0CFP->getValue() - N1CFP->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000412 N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000413 // fold (A+B)-A -> B
414 if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N1 &&
415 !MVT::isFloatingPoint(N1.getValueType()))
Nate Begeman83e75ec2005-09-06 04:43:02 +0000416 return N0.getOperand(1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000417 // fold (A+B)-B -> A
418 if (N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1 &&
419 !MVT::isFloatingPoint(N1.getValueType()))
Nate Begeman83e75ec2005-09-06 04:43:02 +0000420 return N0.getOperand(0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000421 // fold (A-(-B)) -> A+B
422 if (N1.getOpcode() == ISD::FNEG)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000423 return DAG.getNode(ISD::ADD, N0.getValueType(), N0, N1.getOperand(0));
424 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000425}
426
Nate Begeman83e75ec2005-09-06 04:43:02 +0000427SDOperand DAGCombiner::visitMUL(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000428 SDOperand N0 = N->getOperand(0);
429 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000430 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
431 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
432 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
433 ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
Nate Begeman223df222005-09-08 20:18:10 +0000434 MVT::ValueType VT = N0.getValueType();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000435
436 // fold (mul c1, c2) -> c1*c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000437 if (N0C && N1C)
438 return DAG.getConstant(N0C->getValue() * N1C->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000439 N->getValueType(0));
Nate Begeman99801192005-09-07 23:25:52 +0000440 // canonicalize constant to RHS
441 if (N0C && !N1C) {
442 std::swap(N0, N1);
443 std::swap(N0C, N1C);
444 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000445 // fold (mul x, 0) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000446 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000447 return N1;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000448 // fold (mul x, -1) -> 0-x
Nate Begeman646d7e22005-09-02 21:18:40 +0000449 if (N1C && N1C->isAllOnesValue())
Nate Begeman1d4d4142005-09-01 00:19:25 +0000450 return DAG.getNode(ISD::SUB, N->getValueType(0),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000451 DAG.getConstant(0, N->getValueType(0)), N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000452 // fold (mul x, (1 << c)) -> x << c
Nate Begeman646d7e22005-09-02 21:18:40 +0000453 if (N1C && isPowerOf2_64(N1C->getValue()))
Nate Begeman1d4d4142005-09-01 00:19:25 +0000454 return DAG.getNode(ISD::SHL, N->getValueType(0), N0,
Nate Begeman646d7e22005-09-02 21:18:40 +0000455 DAG.getConstant(Log2_64(N1C->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000456 TLI.getShiftAmountTy()));
Nate Begeman223df222005-09-08 20:18:10 +0000457 // fold (mul (mul x, c1), c2) -> (mul x, c1*c2)
458 if (N1C && N0.getOpcode() == ISD::MUL) {
459 ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand(0));
460 ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
461 if (N00C)
462 return DAG.getNode(ISD::MUL, VT, N0.getOperand(1),
463 DAG.getConstant(N1C->getValue()*N00C->getValue(), VT));
464 if (N01C)
465 return DAG.getNode(ISD::MUL, VT, N0.getOperand(0),
466 DAG.getConstant(N1C->getValue()*N01C->getValue(), VT));
467 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000468 // fold floating point (mul c1, c2) -> c1*c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000469 if (N0CFP && N1CFP)
470 return DAG.getConstantFP(N0CFP->getValue() * N1CFP->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000471 N->getValueType(0));
472 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000473}
474
Nate Begeman83e75ec2005-09-06 04:43:02 +0000475SDOperand DAGCombiner::visitSDIV(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000476 SDOperand N0 = N->getOperand(0);
477 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000478 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val);
479 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
480 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0.Val);
481 ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1.Val);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000482
483 // fold (sdiv c1, c2) -> c1/c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000484 if (N0C && N1C && !N1C->isNullValue())
485 return DAG.getConstant(N0C->getSignExtended() / N1C->getSignExtended(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000486 N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000487 // fold floating point (sdiv c1, c2) -> c1/c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000488 if (N0CFP && N1CFP)
489 return DAG.getConstantFP(N0CFP->getValue() / N1CFP->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000490 N->getValueType(0));
491 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000492}
493
Nate Begeman83e75ec2005-09-06 04:43:02 +0000494SDOperand DAGCombiner::visitUDIV(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000495 SDOperand N0 = N->getOperand(0);
496 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000497 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val);
498 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000499
500 // fold (udiv c1, c2) -> c1/c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000501 if (N0C && N1C && !N1C->isNullValue())
502 return DAG.getConstant(N0C->getValue() / N1C->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000503 N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000504 // fold (udiv x, (1 << c)) -> x >>u c
Nate Begeman646d7e22005-09-02 21:18:40 +0000505 if (N1C && isPowerOf2_64(N1C->getValue()))
Nate Begeman1d4d4142005-09-01 00:19:25 +0000506 return DAG.getNode(ISD::SRL, N->getValueType(0), N0,
Nate Begeman646d7e22005-09-02 21:18:40 +0000507 DAG.getConstant(Log2_64(N1C->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000508 TLI.getShiftAmountTy()));
509 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000510}
511
Nate Begeman83e75ec2005-09-06 04:43:02 +0000512SDOperand DAGCombiner::visitSREM(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000513 SDOperand N0 = N->getOperand(0);
514 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000515 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
516 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
517 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
518 ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000519
520 // fold (srem c1, c2) -> c1%c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000521 if (N0C && N1C && !N1C->isNullValue())
522 return DAG.getConstant(N0C->getSignExtended() % N1C->getSignExtended(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000523 N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000524 // fold floating point (srem c1, c2) -> fmod(c1, c2)
Nate Begeman646d7e22005-09-02 21:18:40 +0000525 if (N0CFP && N1CFP)
526 return DAG.getConstantFP(fmod(N0CFP->getValue(),N1CFP->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000527 N->getValueType(0));
528 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000529}
530
Nate Begeman83e75ec2005-09-06 04:43:02 +0000531SDOperand DAGCombiner::visitUREM(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000532 SDOperand N0 = N->getOperand(0);
533 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000534 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
535 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000536
537 // fold (urem c1, c2) -> c1%c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000538 if (N0C && N1C && !N1C->isNullValue())
539 return DAG.getConstant(N0C->getValue() % N1C->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000540 N->getValueType(0));
Nate Begeman646d7e22005-09-02 21:18:40 +0000541 // FIXME: c2 power of 2 -> mask?
Nate Begeman83e75ec2005-09-06 04:43:02 +0000542 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000543}
544
Nate Begeman83e75ec2005-09-06 04:43:02 +0000545SDOperand DAGCombiner::visitMULHS(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000546 SDOperand N0 = N->getOperand(0);
547 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000548 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000549
550 // fold (mulhs x, 0) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000551 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000552 return N1;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000553 // fold (mulhs x, 1) -> (sra x, size(x)-1)
Nate Begeman646d7e22005-09-02 21:18:40 +0000554 if (N1C && N1C->getValue() == 1)
Nate Begeman1d4d4142005-09-01 00:19:25 +0000555 return DAG.getNode(ISD::SRA, N0.getValueType(), N0,
556 DAG.getConstant(MVT::getSizeInBits(N0.getValueType())-1,
Nate Begeman83e75ec2005-09-06 04:43:02 +0000557 TLI.getShiftAmountTy()));
558 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000559}
560
Nate Begeman83e75ec2005-09-06 04:43:02 +0000561SDOperand DAGCombiner::visitMULHU(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000562 SDOperand N0 = N->getOperand(0);
563 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000564 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000565
566 // fold (mulhu x, 0) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000567 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000568 return N1;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000569 // fold (mulhu x, 1) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000570 if (N1C && N1C->getValue() == 1)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000571 return DAG.getConstant(0, N0.getValueType());
572 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000573}
574
Nate Begeman83e75ec2005-09-06 04:43:02 +0000575SDOperand DAGCombiner::visitAND(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000576 SDOperand N0 = N->getOperand(0);
577 SDOperand N1 = N->getOperand(1);
Nate Begeman39ee1ac2005-09-09 19:49:52 +0000578 SDOperand LL, LR, RL, RR, CC0, CC1;
Nate Begeman646d7e22005-09-02 21:18:40 +0000579 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
580 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000581 MVT::ValueType VT = N1.getValueType();
Nate Begeman83e75ec2005-09-06 04:43:02 +0000582 unsigned OpSizeInBits = MVT::getSizeInBits(VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000583
584 // fold (and c1, c2) -> c1&c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000585 if (N0C && N1C)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000586 return DAG.getConstant(N0C->getValue() & N1C->getValue(), VT);
Nate Begeman99801192005-09-07 23:25:52 +0000587 // canonicalize constant to RHS
588 if (N0C && !N1C) {
589 std::swap(N0, N1);
590 std::swap(N0C, N1C);
591 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000592 // fold (and x, -1) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000593 if (N1C && N1C->isAllOnesValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000594 return N0;
595 // if (and x, c) is known to be zero, return 0
596 if (N1C && MaskedValueIsZero(SDOperand(N, 0), ~0ULL >> (64-OpSizeInBits),TLI))
597 return DAG.getConstant(0, VT);
598 // fold (and x, c) -> x iff (x & ~c) == 0
599 if (N1C && MaskedValueIsZero(N0,~N1C->getValue() & (~0ULL>>(64-OpSizeInBits)),
600 TLI))
601 return N0;
Nate Begeman223df222005-09-08 20:18:10 +0000602 // fold (and (and x, c1), c2) -> (and x, c1^c2)
603 if (N1C && N0.getOpcode() == ISD::AND) {
604 ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand(0));
605 ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
606 if (N00C)
607 return DAG.getNode(ISD::AND, VT, N0.getOperand(1),
608 DAG.getConstant(N1C->getValue()&N00C->getValue(), VT));
609 if (N01C)
610 return DAG.getNode(ISD::AND, VT, N0.getOperand(0),
611 DAG.getConstant(N1C->getValue()&N01C->getValue(), VT));
612 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000613 // fold (and (sign_extend_inreg x, i16 to i32), 1) -> (and x, 1)
614 if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG) {
615 unsigned ExtendBits =
616 MVT::getSizeInBits(cast<VTSDNode>(N0.getOperand(1))->getVT());
Nate Begeman646d7e22005-09-02 21:18:40 +0000617 if ((N1C->getValue() & (~0ULL << ExtendBits)) == 0)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000618 return DAG.getNode(ISD::AND, VT, N0.getOperand(0), N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000619 }
620 // fold (and (or x, 0xFFFF), 0xFF) -> 0xFF
621 if (N0.getOpcode() == ISD::OR)
622 if (ConstantSDNode *ORI = dyn_cast<ConstantSDNode>(N0.getOperand(1)))
Nate Begeman646d7e22005-09-02 21:18:40 +0000623 if ((ORI->getValue() & N1C->getValue()) == N1C->getValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000624 return N1;
Nate Begeman39ee1ac2005-09-09 19:49:52 +0000625 // fold (and (setcc x), (setcc y)) -> (setcc (and x, y))
626 if (isSetCCEquivalent(N0, LL, LR, CC0) && isSetCCEquivalent(N1, RL, RR, CC1)){
627 ISD::CondCode Op0 = cast<CondCodeSDNode>(CC0)->get();
628 ISD::CondCode Op1 = cast<CondCodeSDNode>(CC1)->get();
629
630 if (LR == RR && isa<ConstantSDNode>(LR) && Op0 == Op1 &&
631 MVT::isInteger(LL.getValueType())) {
632 // fold (X == 0) & (Y == 0) -> (X|Y == 0)
633 if (cast<ConstantSDNode>(LR)->getValue() == 0 && Op1 == ISD::SETEQ) {
634 SDOperand ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
635 WorkList.push_back(ORNode.Val);
636 return DAG.getSetCC(VT, ORNode, LR, Op1);
637 }
638 // fold (X == -1) & (Y == -1) -> (X&Y == -1)
639 if (cast<ConstantSDNode>(LR)->isAllOnesValue() && Op1 == ISD::SETEQ) {
640 SDOperand ANDNode = DAG.getNode(ISD::AND, LR.getValueType(), LL, RL);
641 WorkList.push_back(ANDNode.Val);
642 return DAG.getSetCC(VT, ANDNode, LR, Op1);
643 }
644 // fold (X > -1) & (Y > -1) -> (X|Y > -1)
645 if (cast<ConstantSDNode>(LR)->isAllOnesValue() && Op1 == ISD::SETGT) {
646 SDOperand ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
647 WorkList.push_back(ORNode.Val);
648 return DAG.getSetCC(VT, ORNode, LR, Op1);
649 }
650 }
651 // canonicalize equivalent to ll == rl
652 if (LL == RR && LR == RL) {
653 Op1 = ISD::getSetCCSwappedOperands(Op1);
654 std::swap(RL, RR);
655 }
656 if (LL == RL && LR == RR) {
657 bool isInteger = MVT::isInteger(LL.getValueType());
658 ISD::CondCode Result = ISD::getSetCCAndOperation(Op0, Op1, isInteger);
659 if (Result != ISD::SETCC_INVALID)
660 return DAG.getSetCC(N0.getValueType(), LL, LR, Result);
661 }
662 }
663 // fold (and (zext x), (zext y)) -> (zext (and x, y))
664 if (N0.getOpcode() == ISD::ZERO_EXTEND &&
665 N1.getOpcode() == ISD::ZERO_EXTEND &&
666 N0.getOperand(0).getValueType() == N1.getOperand(0).getValueType()) {
667 SDOperand ANDNode = DAG.getNode(ISD::AND, N0.getOperand(0).getValueType(),
668 N0.getOperand(0), N1.getOperand(0));
669 WorkList.push_back(ANDNode.Val);
670 return DAG.getNode(ISD::ZERO_EXTEND, VT, ANDNode);
671 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000672 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000673}
674
Nate Begeman83e75ec2005-09-06 04:43:02 +0000675SDOperand DAGCombiner::visitOR(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000676 SDOperand N0 = N->getOperand(0);
677 SDOperand N1 = N->getOperand(1);
Nate Begeman39ee1ac2005-09-09 19:49:52 +0000678 SDOperand LL, LR, RL, RR, CC0, CC1;
Nate Begeman646d7e22005-09-02 21:18:40 +0000679 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
680 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman83e75ec2005-09-06 04:43:02 +0000681 MVT::ValueType VT = N1.getValueType();
682 unsigned OpSizeInBits = MVT::getSizeInBits(VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000683
684 // fold (or c1, c2) -> c1|c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000685 if (N0C && N1C)
686 return DAG.getConstant(N0C->getValue() | N1C->getValue(),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000687 N->getValueType(0));
Nate Begeman99801192005-09-07 23:25:52 +0000688 // canonicalize constant to RHS
689 if (N0C && !N1C) {
690 std::swap(N0, N1);
691 std::swap(N0C, N1C);
692 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000693 // fold (or x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000694 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000695 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000696 // fold (or x, -1) -> -1
Nate Begeman646d7e22005-09-02 21:18:40 +0000697 if (N1C && N1C->isAllOnesValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000698 return N1;
699 // fold (or x, c) -> c iff (x & ~c) == 0
700 if (N1C && MaskedValueIsZero(N0,~N1C->getValue() & (~0ULL>>(64-OpSizeInBits)),
701 TLI))
702 return N1;
Nate Begeman223df222005-09-08 20:18:10 +0000703 // fold (or (or x, c1), c2) -> (or x, c1|c2)
704 if (N1C && N0.getOpcode() == ISD::OR) {
705 ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand(0));
706 ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
707 if (N00C)
708 return DAG.getNode(ISD::OR, VT, N0.getOperand(1),
709 DAG.getConstant(N1C->getValue()|N00C->getValue(), VT));
710 if (N01C)
711 return DAG.getNode(ISD::OR, VT, N0.getOperand(0),
712 DAG.getConstant(N1C->getValue()|N01C->getValue(), VT));
713 }
Nate Begeman39ee1ac2005-09-09 19:49:52 +0000714 // fold (or (setcc x), (setcc y)) -> (setcc (or x, y))
715 if (isSetCCEquivalent(N0, LL, LR, CC0) && isSetCCEquivalent(N1, RL, RR, CC1)){
716 ISD::CondCode Op0 = cast<CondCodeSDNode>(CC0)->get();
717 ISD::CondCode Op1 = cast<CondCodeSDNode>(CC1)->get();
718
719 if (LR == RR && isa<ConstantSDNode>(LR) && Op0 == Op1 &&
720 MVT::isInteger(LL.getValueType())) {
721 // fold (X != 0) | (Y != 0) -> (X|Y != 0)
722 // fold (X < 0) | (Y < 0) -> (X|Y < 0)
723 if (cast<ConstantSDNode>(LR)->getValue() == 0 &&
724 (Op1 == ISD::SETNE || Op1 == ISD::SETLT)) {
725 SDOperand ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
726 WorkList.push_back(ORNode.Val);
727 return DAG.getSetCC(VT, ORNode, LR, Op1);
728 }
729 // fold (X != -1) | (Y != -1) -> (X&Y != -1)
730 // fold (X > -1) | (Y > -1) -> (X&Y > -1)
731 if (cast<ConstantSDNode>(LR)->isAllOnesValue() &&
732 (Op1 == ISD::SETNE || Op1 == ISD::SETGT)) {
733 SDOperand ANDNode = DAG.getNode(ISD::AND, LR.getValueType(), LL, RL);
734 WorkList.push_back(ANDNode.Val);
735 return DAG.getSetCC(VT, ANDNode, LR, Op1);
736 }
737 }
738 // canonicalize equivalent to ll == rl
739 if (LL == RR && LR == RL) {
740 Op1 = ISD::getSetCCSwappedOperands(Op1);
741 std::swap(RL, RR);
742 }
743 if (LL == RL && LR == RR) {
744 bool isInteger = MVT::isInteger(LL.getValueType());
745 ISD::CondCode Result = ISD::getSetCCOrOperation(Op0, Op1, isInteger);
746 if (Result != ISD::SETCC_INVALID)
747 return DAG.getSetCC(N0.getValueType(), LL, LR, Result);
748 }
749 }
750 // fold (or (zext x), (zext y)) -> (zext (or x, y))
751 if (N0.getOpcode() == ISD::ZERO_EXTEND &&
752 N1.getOpcode() == ISD::ZERO_EXTEND &&
753 N0.getOperand(0).getValueType() == N1.getOperand(0).getValueType()) {
754 SDOperand ORNode = DAG.getNode(ISD::OR, N0.getOperand(0).getValueType(),
755 N0.getOperand(0), N1.getOperand(0));
756 WorkList.push_back(ORNode.Val);
757 return DAG.getNode(ISD::ZERO_EXTEND, VT, ORNode);
758 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000759 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000760}
761
Nate Begeman83e75ec2005-09-06 04:43:02 +0000762SDOperand DAGCombiner::visitXOR(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000763 SDOperand N0 = N->getOperand(0);
764 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000765 SDOperand LHS, RHS, CC;
766 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
767 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000768 MVT::ValueType VT = N0.getValueType();
769
770 // fold (xor c1, c2) -> c1^c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000771 if (N0C && N1C)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000772 return DAG.getConstant(N0C->getValue() ^ N1C->getValue(), VT);
Nate Begeman99801192005-09-07 23:25:52 +0000773 // canonicalize constant to RHS
774 if (N0C && !N1C) {
775 std::swap(N0, N1);
776 std::swap(N0C, N1C);
777 }
Nate Begeman1d4d4142005-09-01 00:19:25 +0000778 // fold (xor x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000779 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000780 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000781 // fold !(x cc y) -> (x !cc y)
Nate Begeman646d7e22005-09-02 21:18:40 +0000782 if (N1C && N1C->getValue() == 1 && isSetCCEquivalent(N0, LHS, RHS, CC)) {
783 bool isInt = MVT::isInteger(LHS.getValueType());
784 ISD::CondCode NotCC = ISD::getSetCCInverse(cast<CondCodeSDNode>(CC)->get(),
785 isInt);
786 if (N0.getOpcode() == ISD::SETCC)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000787 return DAG.getSetCC(VT, LHS, RHS, NotCC);
Nate Begeman646d7e22005-09-02 21:18:40 +0000788 if (N0.getOpcode() == ISD::SELECT_CC)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000789 return DAG.getSelectCC(LHS, RHS, N0.getOperand(2),N0.getOperand(3),NotCC);
Nate Begeman646d7e22005-09-02 21:18:40 +0000790 assert(0 && "Unhandled SetCC Equivalent!");
791 abort();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000792 }
Nate Begeman99801192005-09-07 23:25:52 +0000793 // fold !(x or y) -> (!x and !y) iff x or y are setcc
794 if (N1C && N1C->getValue() == 1 &&
795 (N0.getOpcode() == ISD::OR || N0.getOpcode() == ISD::AND)) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000796 SDOperand LHS = N0.getOperand(0), RHS = N0.getOperand(1);
Nate Begeman99801192005-09-07 23:25:52 +0000797 if (isOneUseSetCC(RHS) || isOneUseSetCC(LHS)) {
798 unsigned NewOpcode = N0.getOpcode() == ISD::AND ? ISD::OR : ISD::AND;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000799 LHS = DAG.getNode(ISD::XOR, VT, LHS, N1); // RHS = ~LHS
800 RHS = DAG.getNode(ISD::XOR, VT, RHS, N1); // RHS = ~RHS
Nate Begeman99801192005-09-07 23:25:52 +0000801 WorkList.push_back(LHS.Val); WorkList.push_back(RHS.Val);
802 return DAG.getNode(NewOpcode, VT, LHS, RHS);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000803 }
804 }
Nate Begeman99801192005-09-07 23:25:52 +0000805 // fold !(x or y) -> (!x and !y) iff x or y are constants
806 if (N1C && N1C->isAllOnesValue() &&
807 (N0.getOpcode() == ISD::OR || N0.getOpcode() == ISD::AND)) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000808 SDOperand LHS = N0.getOperand(0), RHS = N0.getOperand(1);
Nate Begeman99801192005-09-07 23:25:52 +0000809 if (isa<ConstantSDNode>(RHS) || isa<ConstantSDNode>(LHS)) {
810 unsigned NewOpcode = N0.getOpcode() == ISD::AND ? ISD::OR : ISD::AND;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000811 LHS = DAG.getNode(ISD::XOR, VT, LHS, N1); // RHS = ~LHS
812 RHS = DAG.getNode(ISD::XOR, VT, RHS, N1); // RHS = ~RHS
Nate Begeman99801192005-09-07 23:25:52 +0000813 WorkList.push_back(LHS.Val); WorkList.push_back(RHS.Val);
814 return DAG.getNode(NewOpcode, VT, LHS, RHS);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000815 }
816 }
Nate Begeman223df222005-09-08 20:18:10 +0000817 // fold (xor (xor x, c1), c2) -> (xor x, c1^c2)
818 if (N1C && N0.getOpcode() == ISD::XOR) {
819 ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand(0));
820 ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N0.getOperand(1));
821 if (N00C)
822 return DAG.getNode(ISD::XOR, VT, N0.getOperand(1),
823 DAG.getConstant(N1C->getValue()^N00C->getValue(), VT));
824 if (N01C)
825 return DAG.getNode(ISD::XOR, VT, N0.getOperand(0),
826 DAG.getConstant(N1C->getValue()^N01C->getValue(), VT));
827 }
828 // fold (xor x, x) -> 0
829 if (N0 == N1)
830 return DAG.getConstant(0, VT);
Nate Begeman39ee1ac2005-09-09 19:49:52 +0000831 // fold (xor (zext x), (zext y)) -> (zext (xor x, y))
832 if (N0.getOpcode() == ISD::ZERO_EXTEND &&
833 N1.getOpcode() == ISD::ZERO_EXTEND &&
834 N0.getOperand(0).getValueType() == N1.getOperand(0).getValueType()) {
835 SDOperand XORNode = DAG.getNode(ISD::XOR, N0.getOperand(0).getValueType(),
836 N0.getOperand(0), N1.getOperand(0));
837 WorkList.push_back(XORNode.Val);
838 return DAG.getNode(ISD::ZERO_EXTEND, VT, XORNode);
839 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000840 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000841}
842
Nate Begeman83e75ec2005-09-06 04:43:02 +0000843SDOperand DAGCombiner::visitSHL(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000844 SDOperand N0 = N->getOperand(0);
845 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000846 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
847 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000848 MVT::ValueType VT = N0.getValueType();
849 unsigned OpSizeInBits = MVT::getSizeInBits(VT);
850
851 // fold (shl c1, c2) -> c1<<c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000852 if (N0C && N1C)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000853 return DAG.getConstant(N0C->getValue() << N1C->getValue(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000854 // fold (shl 0, x) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000855 if (N0C && N0C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000856 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000857 // fold (shl x, c >= size(x)) -> undef
Nate Begeman646d7e22005-09-02 21:18:40 +0000858 if (N1C && N1C->getValue() >= OpSizeInBits)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000859 return DAG.getNode(ISD::UNDEF, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000860 // fold (shl x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000861 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000862 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000863 // if (shl x, c) is known to be zero, return 0
Nate Begeman83e75ec2005-09-06 04:43:02 +0000864 if (N1C && MaskedValueIsZero(SDOperand(N, 0), ~0ULL >> (64-OpSizeInBits),TLI))
865 return DAG.getConstant(0, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000866 // fold (shl (shl x, c1), c2) -> 0 or (shl x, c1+c2)
Nate Begeman646d7e22005-09-02 21:18:40 +0000867 if (N1C && N0.getOpcode() == ISD::SHL &&
Nate Begeman1d4d4142005-09-01 00:19:25 +0000868 N0.getOperand(1).getOpcode() == ISD::Constant) {
869 uint64_t c1 = cast<ConstantSDNode>(N0.getOperand(1))->getValue();
Nate Begeman646d7e22005-09-02 21:18:40 +0000870 uint64_t c2 = N1C->getValue();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000871 if (c1 + c2 > OpSizeInBits)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000872 return DAG.getConstant(0, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000873 return DAG.getNode(ISD::SHL, VT, N0.getOperand(0),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000874 DAG.getConstant(c1 + c2, N1.getValueType()));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000875 }
876 // fold (shl (srl x, c1), c2) -> (shl (and x, -1 << c1), c2-c1) or
877 // (srl (and x, -1 << c1), c1-c2)
Nate Begeman646d7e22005-09-02 21:18:40 +0000878 if (N1C && N0.getOpcode() == ISD::SRL &&
Nate Begeman1d4d4142005-09-01 00:19:25 +0000879 N0.getOperand(1).getOpcode() == ISD::Constant) {
880 uint64_t c1 = cast<ConstantSDNode>(N0.getOperand(1))->getValue();
Nate Begeman646d7e22005-09-02 21:18:40 +0000881 uint64_t c2 = N1C->getValue();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000882 SDOperand Mask = DAG.getNode(ISD::AND, VT, N0.getOperand(0),
883 DAG.getConstant(~0ULL << c1, VT));
884 if (c2 > c1)
885 return DAG.getNode(ISD::SHL, VT, Mask,
Nate Begeman83e75ec2005-09-06 04:43:02 +0000886 DAG.getConstant(c2-c1, N1.getValueType()));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000887 else
Nate Begeman83e75ec2005-09-06 04:43:02 +0000888 return DAG.getNode(ISD::SRL, VT, Mask,
889 DAG.getConstant(c1-c2, N1.getValueType()));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000890 }
891 // fold (shl (sra x, c1), c1) -> (and x, -1 << c1)
Nate Begeman646d7e22005-09-02 21:18:40 +0000892 if (N1C && N0.getOpcode() == ISD::SRA && N1 == N0.getOperand(1))
Nate Begeman4ebd8052005-09-01 23:24:04 +0000893 return DAG.getNode(ISD::AND, VT, N0.getOperand(0),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000894 DAG.getConstant(~0ULL << N1C->getValue(), VT));
895 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000896}
897
Nate Begeman83e75ec2005-09-06 04:43:02 +0000898SDOperand DAGCombiner::visitSRA(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000899 SDOperand N0 = N->getOperand(0);
900 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000901 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
902 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000903 MVT::ValueType VT = N0.getValueType();
904 unsigned OpSizeInBits = MVT::getSizeInBits(VT);
905
906 // fold (sra c1, c2) -> c1>>c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000907 if (N0C && N1C)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000908 return DAG.getConstant(N0C->getSignExtended() >> N1C->getValue(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000909 // fold (sra 0, x) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000910 if (N0C && N0C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000911 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000912 // fold (sra -1, x) -> -1
Nate Begeman646d7e22005-09-02 21:18:40 +0000913 if (N0C && N0C->isAllOnesValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000914 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000915 // fold (sra x, c >= size(x)) -> undef
Nate Begeman646d7e22005-09-02 21:18:40 +0000916 if (N1C && N1C->getValue() >= OpSizeInBits)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000917 return DAG.getNode(ISD::UNDEF, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000918 // fold (sra x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000919 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000920 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000921 // If the sign bit is known to be zero, switch this to a SRL.
Nate Begeman646d7e22005-09-02 21:18:40 +0000922 if (N1C && MaskedValueIsZero(N0, (1ULL << (OpSizeInBits-1)), TLI))
Nate Begeman83e75ec2005-09-06 04:43:02 +0000923 return DAG.getNode(ISD::SRL, VT, N0, N1);
924 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000925}
926
Nate Begeman83e75ec2005-09-06 04:43:02 +0000927SDOperand DAGCombiner::visitSRL(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000928 SDOperand N0 = N->getOperand(0);
929 SDOperand N1 = N->getOperand(1);
Nate Begeman646d7e22005-09-02 21:18:40 +0000930 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
931 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000932 MVT::ValueType VT = N0.getValueType();
933 unsigned OpSizeInBits = MVT::getSizeInBits(VT);
934
935 // fold (srl c1, c2) -> c1 >>u c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000936 if (N0C && N1C)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000937 return DAG.getConstant(N0C->getValue() >> N1C->getValue(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000938 // fold (srl 0, x) -> 0
Nate Begeman646d7e22005-09-02 21:18:40 +0000939 if (N0C && N0C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000940 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000941 // fold (srl x, c >= size(x)) -> undef
Nate Begeman646d7e22005-09-02 21:18:40 +0000942 if (N1C && N1C->getValue() >= OpSizeInBits)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000943 return DAG.getNode(ISD::UNDEF, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000944 // fold (srl x, 0) -> x
Nate Begeman646d7e22005-09-02 21:18:40 +0000945 if (N1C && N1C->isNullValue())
Nate Begeman83e75ec2005-09-06 04:43:02 +0000946 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +0000947 // if (srl x, c) is known to be zero, return 0
Nate Begeman83e75ec2005-09-06 04:43:02 +0000948 if (N1C && MaskedValueIsZero(SDOperand(N, 0), ~0ULL >> (64-OpSizeInBits),TLI))
949 return DAG.getConstant(0, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000950 // fold (srl (srl x, c1), c2) -> 0 or (srl x, c1+c2)
Nate Begeman646d7e22005-09-02 21:18:40 +0000951 if (N1C && N0.getOpcode() == ISD::SRL &&
Nate Begeman1d4d4142005-09-01 00:19:25 +0000952 N0.getOperand(1).getOpcode() == ISD::Constant) {
953 uint64_t c1 = cast<ConstantSDNode>(N0.getOperand(1))->getValue();
Nate Begeman646d7e22005-09-02 21:18:40 +0000954 uint64_t c2 = N1C->getValue();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000955 if (c1 + c2 > OpSizeInBits)
Nate Begeman83e75ec2005-09-06 04:43:02 +0000956 return DAG.getConstant(0, VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000957 return DAG.getNode(ISD::SRL, VT, N0.getOperand(0),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000958 DAG.getConstant(c1 + c2, N1.getValueType()));
Nate Begeman1d4d4142005-09-01 00:19:25 +0000959 }
Nate Begeman83e75ec2005-09-06 04:43:02 +0000960 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000961}
962
Nate Begeman83e75ec2005-09-06 04:43:02 +0000963SDOperand DAGCombiner::visitCTLZ(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000964 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +0000965 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000966
967 // fold (ctlz c1) -> c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000968 if (N0C)
969 return DAG.getConstant(CountLeadingZeros_64(N0C->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000970 N0.getValueType());
971 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000972}
973
Nate Begeman83e75ec2005-09-06 04:43:02 +0000974SDOperand DAGCombiner::visitCTTZ(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000975 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +0000976 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000977
978 // fold (cttz c1) -> c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000979 if (N0C)
980 return DAG.getConstant(CountTrailingZeros_64(N0C->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000981 N0.getValueType());
982 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000983}
984
Nate Begeman83e75ec2005-09-06 04:43:02 +0000985SDOperand DAGCombiner::visitCTPOP(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000986 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +0000987 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000988
989 // fold (ctpop c1) -> c2
Nate Begeman646d7e22005-09-02 21:18:40 +0000990 if (N0C)
991 return DAG.getConstant(CountPopulation_64(N0C->getValue()),
Nate Begeman83e75ec2005-09-06 04:43:02 +0000992 N0.getValueType());
993 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +0000994}
995
Nate Begeman83e75ec2005-09-06 04:43:02 +0000996SDOperand DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +0000997 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +0000998 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +0000999 MVT::ValueType VT = N->getValueType(0);
1000
Nate Begeman1d4d4142005-09-01 00:19:25 +00001001 // fold (sext c1) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001002 if (N0C)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001003 return DAG.getConstant(N0C->getSignExtended(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001004 // fold (sext (sext x)) -> (sext x)
1005 if (N0.getOpcode() == ISD::SIGN_EXTEND)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001006 return DAG.getNode(ISD::SIGN_EXTEND, VT, N0.getOperand(0));
1007 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001008}
1009
Nate Begeman83e75ec2005-09-06 04:43:02 +00001010SDOperand DAGCombiner::visitZERO_EXTEND(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001011 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001012 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001013 MVT::ValueType VT = N->getValueType(0);
1014
Nate Begeman1d4d4142005-09-01 00:19:25 +00001015 // fold (zext c1) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001016 if (N0C)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001017 return DAG.getConstant(N0C->getValue(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001018 // fold (zext (zext x)) -> (zext x)
1019 if (N0.getOpcode() == ISD::ZERO_EXTEND)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001020 return DAG.getNode(ISD::ZERO_EXTEND, VT, N0.getOperand(0));
1021 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001022}
1023
Nate Begeman83e75ec2005-09-06 04:43:02 +00001024SDOperand DAGCombiner::visitSIGN_EXTEND_INREG(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001025 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001026 SDOperand N1 = N->getOperand(1);
1027 SDOperand LHS, RHS, CC;
1028 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001029 MVT::ValueType VT = N->getValueType(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001030 MVT::ValueType EVT = cast<VTSDNode>(N1)->getVT();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001031
Nate Begeman1d4d4142005-09-01 00:19:25 +00001032 // fold (sext_in_reg c1) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001033 if (N0C) {
1034 SDOperand Truncate = DAG.getConstant(N0C->getValue(), EVT);
Nate Begeman83e75ec2005-09-06 04:43:02 +00001035 return DAG.getNode(ISD::SIGN_EXTEND, VT, Truncate);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001036 }
Nate Begeman646d7e22005-09-02 21:18:40 +00001037 // fold (sext_in_reg (sext_in_reg x, VT2), VT1) -> (sext_in_reg x, minVT) pt1
Nate Begeman1d4d4142005-09-01 00:19:25 +00001038 if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG &&
Nate Begeman646d7e22005-09-02 21:18:40 +00001039 cast<VTSDNode>(N0.getOperand(1))->getVT() < EVT) {
Nate Begeman83e75ec2005-09-06 04:43:02 +00001040 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001041 }
Nate Begeman646d7e22005-09-02 21:18:40 +00001042 // fold (sext_in_reg (sext_in_reg x, VT2), VT1) -> (sext_in_reg x, minVT) pt2
1043 if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG &&
1044 EVT < cast<VTSDNode>(N0.getOperand(1))->getVT()) {
Nate Begeman83e75ec2005-09-06 04:43:02 +00001045 return DAG.getNode(ISD::SIGN_EXTEND_INREG, VT, N0.getOperand(0), N1);
Nate Begeman646d7e22005-09-02 21:18:40 +00001046 }
Nate Begeman1d4d4142005-09-01 00:19:25 +00001047 // fold (sext_in_reg (assert_sext x)) -> (assert_sext x)
1048 if (N0.getOpcode() == ISD::AssertSext &&
1049 cast<VTSDNode>(N0.getOperand(1))->getVT() <= EVT) {
Nate Begeman83e75ec2005-09-06 04:43:02 +00001050 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001051 }
1052 // fold (sext_in_reg (sextload x)) -> (sextload x)
1053 if (N0.getOpcode() == ISD::SEXTLOAD &&
1054 cast<VTSDNode>(N0.getOperand(3))->getVT() <= EVT) {
Nate Begeman83e75ec2005-09-06 04:43:02 +00001055 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001056 }
Nate Begeman4ebd8052005-09-01 23:24:04 +00001057 // fold (sext_in_reg (setcc x)) -> setcc x iff (setcc x) == 0 or -1
Nate Begeman646d7e22005-09-02 21:18:40 +00001058 // FIXME: teach isSetCCEquivalent about 0, -1 and then use it here
Nate Begeman1d4d4142005-09-01 00:19:25 +00001059 if (N0.getOpcode() == ISD::SETCC &&
1060 TLI.getSetCCResultContents() ==
1061 TargetLowering::ZeroOrNegativeOneSetCCResult)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001062 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001063 // FIXME: this code is currently just ported over from SelectionDAG.cpp
1064 // we probably actually want to handle this in two pieces. Rather than
1065 // checking all the top bits for zero, just check the sign bit here and turn
1066 // it into a zero extend inreg (AND with constant).
1067 // then, let the code for AND figure out if the mask is superfluous rather
1068 // than doing so here.
1069 if (N0.getOpcode() == ISD::AND &&
1070 N0.getOperand(1).getOpcode() == ISD::Constant) {
1071 uint64_t Mask = cast<ConstantSDNode>(N0.getOperand(1))->getValue();
1072 unsigned NumBits = MVT::getSizeInBits(EVT);
1073 if ((Mask & (~0ULL << (NumBits-1))) == 0)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001074 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001075 }
Nate Begeman83e75ec2005-09-06 04:43:02 +00001076 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001077}
1078
Nate Begeman83e75ec2005-09-06 04:43:02 +00001079SDOperand DAGCombiner::visitTRUNCATE(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001080 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001081 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001082 MVT::ValueType VT = N->getValueType(0);
1083
1084 // noop truncate
1085 if (N0.getValueType() == N->getValueType(0))
Nate Begeman83e75ec2005-09-06 04:43:02 +00001086 return N0;
Nate Begeman1d4d4142005-09-01 00:19:25 +00001087 // fold (truncate c1) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001088 if (N0C)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001089 return DAG.getConstant(N0C->getValue(), VT);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001090 // fold (truncate (truncate x)) -> (truncate x)
1091 if (N0.getOpcode() == ISD::TRUNCATE)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001092 return DAG.getNode(ISD::TRUNCATE, VT, N0.getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001093 // fold (truncate (ext x)) -> (ext x) or (truncate x) or x
1094 if (N0.getOpcode() == ISD::ZERO_EXTEND || N0.getOpcode() == ISD::SIGN_EXTEND){
1095 if (N0.getValueType() < VT)
1096 // if the source is smaller than the dest, we still need an extend
Nate Begeman83e75ec2005-09-06 04:43:02 +00001097 return DAG.getNode(N0.getOpcode(), VT, N0.getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001098 else if (N0.getValueType() > VT)
1099 // if the source is larger than the dest, than we just need the truncate
Nate Begeman83e75ec2005-09-06 04:43:02 +00001100 return DAG.getNode(ISD::TRUNCATE, VT, N0.getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001101 else
1102 // if the source and dest are the same type, we can drop both the extend
1103 // and the truncate
Nate Begeman83e75ec2005-09-06 04:43:02 +00001104 return N0.getOperand(0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001105 }
Nate Begeman83e75ec2005-09-06 04:43:02 +00001106 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001107}
1108
Nate Begeman83e75ec2005-09-06 04:43:02 +00001109SDOperand DAGCombiner::visitSINT_TO_FP(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001110 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001111 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001112
1113 // fold (sint_to_fp c1) -> c1fp
Nate Begeman646d7e22005-09-02 21:18:40 +00001114 if (N0C)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001115 return DAG.getConstantFP(N0C->getSignExtended(), N->getValueType(0));
1116 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001117}
1118
Nate Begeman83e75ec2005-09-06 04:43:02 +00001119SDOperand DAGCombiner::visitUINT_TO_FP(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001120 SDOperand N0 = N->getOperand(0);
Nate Begeman646d7e22005-09-02 21:18:40 +00001121 ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001122
1123 // fold (uint_to_fp c1) -> c1fp
Nate Begeman646d7e22005-09-02 21:18:40 +00001124 if (N0C)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001125 return DAG.getConstantFP(N0C->getValue(), N->getValueType(0));
1126 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001127}
1128
Nate Begeman83e75ec2005-09-06 04:43:02 +00001129SDOperand DAGCombiner::visitFP_TO_SINT(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001130 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001131
1132 // fold (fp_to_sint c1fp) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001133 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001134 return DAG.getConstant((int64_t)N0CFP->getValue(), N->getValueType(0));
1135 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001136}
1137
Nate Begeman83e75ec2005-09-06 04:43:02 +00001138SDOperand DAGCombiner::visitFP_TO_UINT(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001139 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001140
1141 // fold (fp_to_uint c1fp) -> c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001142 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001143 return DAG.getConstant((uint64_t)N0CFP->getValue(), N->getValueType(0));
1144 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001145}
1146
Nate Begeman83e75ec2005-09-06 04:43:02 +00001147SDOperand DAGCombiner::visitFP_ROUND(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001148 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001149
1150 // fold (fp_round c1fp) -> c1fp
Nate Begeman646d7e22005-09-02 21:18:40 +00001151 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001152 return DAG.getConstantFP(N0CFP->getValue(), N->getValueType(0));
1153 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001154}
1155
Nate Begeman83e75ec2005-09-06 04:43:02 +00001156SDOperand DAGCombiner::visitFP_ROUND_INREG(SDNode *N) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001157 SDOperand N0 = N->getOperand(0);
1158 MVT::ValueType VT = N->getValueType(0);
1159 MVT::ValueType EVT = cast<VTSDNode>(N->getOperand(1))->getVT();
Nate Begeman646d7e22005-09-02 21:18:40 +00001160 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001161
Nate Begeman1d4d4142005-09-01 00:19:25 +00001162 // fold (fp_round_inreg c1fp) -> c1fp
Nate Begeman646d7e22005-09-02 21:18:40 +00001163 if (N0CFP) {
1164 SDOperand Round = DAG.getConstantFP(N0CFP->getValue(), EVT);
Nate Begeman83e75ec2005-09-06 04:43:02 +00001165 return DAG.getNode(ISD::FP_EXTEND, VT, Round);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001166 }
Nate Begeman83e75ec2005-09-06 04:43:02 +00001167 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001168}
1169
Nate Begeman83e75ec2005-09-06 04:43:02 +00001170SDOperand DAGCombiner::visitFP_EXTEND(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001171 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001172
1173 // fold (fp_extend c1fp) -> c1fp
Nate Begeman646d7e22005-09-02 21:18:40 +00001174 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001175 return DAG.getConstantFP(N0CFP->getValue(), N->getValueType(0));
1176 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001177}
1178
Nate Begeman83e75ec2005-09-06 04:43:02 +00001179SDOperand DAGCombiner::visitFNEG(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001180 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001181 // fold (neg c1) -> -c1
Nate Begeman646d7e22005-09-02 21:18:40 +00001182 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001183 return DAG.getConstantFP(-N0CFP->getValue(), N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001184 // fold (neg (sub x, y)) -> (sub y, x)
1185 if (N->getOperand(0).getOpcode() == ISD::SUB)
1186 return DAG.getNode(ISD::SUB, N->getValueType(0), N->getOperand(1),
Nate Begeman83e75ec2005-09-06 04:43:02 +00001187 N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001188 // fold (neg (neg x)) -> x
1189 if (N->getOperand(0).getOpcode() == ISD::FNEG)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001190 return N->getOperand(0).getOperand(0);
1191 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001192}
1193
Nate Begeman83e75ec2005-09-06 04:43:02 +00001194SDOperand DAGCombiner::visitFABS(SDNode *N) {
Nate Begeman646d7e22005-09-02 21:18:40 +00001195 ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001196 // fold (fabs c1) -> fabs(c1)
Nate Begeman646d7e22005-09-02 21:18:40 +00001197 if (N0CFP)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001198 return DAG.getConstantFP(fabs(N0CFP->getValue()), N->getValueType(0));
Nate Begeman1d4d4142005-09-01 00:19:25 +00001199 // fold (fabs (fabs x)) -> (fabs x)
1200 if (N->getOperand(0).getOpcode() == ISD::FABS)
Nate Begeman83e75ec2005-09-06 04:43:02 +00001201 return N->getOperand(0);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001202 // fold (fabs (fneg x)) -> (fabs x)
1203 if (N->getOperand(0).getOpcode() == ISD::FNEG)
1204 return DAG.getNode(ISD::FABS, N->getValueType(0),
Nate Begeman83e75ec2005-09-06 04:43:02 +00001205 N->getOperand(0).getOperand(0));
1206 return SDOperand();
Nate Begeman1d4d4142005-09-01 00:19:25 +00001207}
1208
Nate Begeman1d4d4142005-09-01 00:19:25 +00001209// SelectionDAG::Combine - This is the entry point for the file.
1210//
Nate Begeman4ebd8052005-09-01 23:24:04 +00001211void SelectionDAG::Combine(bool RunningAfterLegalize) {
Nate Begeman1d4d4142005-09-01 00:19:25 +00001212 /// run - This is the main entry point to this class.
1213 ///
Nate Begeman4ebd8052005-09-01 23:24:04 +00001214 DAGCombiner(*this).Run(RunningAfterLegalize);
Nate Begeman1d4d4142005-09-01 00:19:25 +00001215}