2005-01-07 07:47:09 +00:00
|
|
|
//===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===//
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-07 07:47:09 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-07 07:47:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the SelectionDAG::Legalize method.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2005-01-15 07:15:18 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2006-12-14 19:17:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2009-01-13 00:35:13 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2008-02-06 22:27:42 +00:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2007-08-16 23:50:06 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2005-01-07 07:47:09 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2005-01-11 05:57:22 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-10-30 08:00:44 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2005-01-15 06:18:18 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
Drop ISD::MEMSET, ISD::MEMMOVE, and ISD::MEMCPY, which are not Legal
on any current target and aren't optimized in DAGCombiner. Instead
of using intermediate nodes, expand the operations, choosing between
simple loads/stores, target-specific code, and library calls,
immediately.
Previously, the code to emit optimized code for these operations
was only used at initial SelectionDAG construction time; now it is
used at all times. This fixes some cases where rep;movs was being
used for small copies where simple loads/stores would be better.
This also cleans up code that checks for alignments less than 4;
let the targets make that decision instead of doing it in
target-independent code. This allows x86 to use rep;movs in
low-alignment cases.
Also, this fixes a bug that resulted in the use of rep;stos for
memsets of 0 with non-constant memory size when the alignment was
at least 4. It's better to use the library in this case, which
can be significantly faster when the size is large.
This also preserves more SourceValue information when memory
intrinsics are lowered into simple loads/stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49572 91177308-0d34-0410-b5e6-96231b3b80d8
2008-04-12 04:36:06 +00:00
|
|
|
#include "llvm/Target/TargetSubtarget.h"
|
2005-05-13 18:50:42 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2005-01-07 07:47:09 +00:00
|
|
|
#include "llvm/Constants.h"
|
2007-01-19 21:13:56 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2009-02-17 01:04:54 +00:00
|
|
|
#include "llvm/Function.h"
|
2009-01-13 00:35:13 +00:00
|
|
|
#include "llvm/GlobalVariable.h"
|
2006-04-02 03:07:27 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-10-28 12:59:45 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2007-02-03 01:12:36 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2006-08-08 01:09:31 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2007-02-04 00:27:56 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2006-03-24 01:17:21 +00:00
|
|
|
#include <map>
|
2005-01-07 07:47:09 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and
|
|
|
|
/// hacks on it until the target machine can handle it. This involves
|
|
|
|
/// eliminating value sizes the machine cannot handle (promoting small sizes to
|
|
|
|
/// large sizes or splitting up large values into small values) as well as
|
|
|
|
/// eliminating operations the machine cannot handle.
|
|
|
|
///
|
|
|
|
/// This code also does a small amount of optimization and recognition of idioms
|
|
|
|
/// as part of its processing. For example, if a target does not support a
|
|
|
|
/// 'setcc' instruction efficiently, but does support 'brcc' instruction, this
|
|
|
|
/// will attempt merge setcc and brc instructions into brcc's.
|
|
|
|
///
|
|
|
|
namespace {
|
2006-06-28 21:58:30 +00:00
|
|
|
class VISIBILITY_HIDDEN SelectionDAGLegalize {
|
2005-01-07 07:47:09 +00:00
|
|
|
TargetLowering &TLI;
|
|
|
|
SelectionDAG &DAG;
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel;
|
2008-12-14 09:43:15 +00:00
|
|
|
bool TypesNeedLegalizing;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Libcall insertion helpers.
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
/// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been
|
|
|
|
/// legalized. We use this to ensure that calls are properly serialized
|
|
|
|
/// against each other, including inserted libcalls.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LastCALLSEQ_END;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
/// IsLegalizingCall - This member is used *only* for purposes of providing
|
2009-02-17 22:15:04 +00:00
|
|
|
/// helpful assertions that a libcall isn't created while another call is
|
2006-02-13 09:18:02 +00:00
|
|
|
/// being legalized (which could lead to non-serialized call sequences).
|
|
|
|
bool IsLegalizingCall;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-04 19:38:14 +00:00
|
|
|
/// IsLegalizingCallArguments - This member is used only for the purpose
|
|
|
|
/// of providing assert to check for LegalizeTypes because legalizing an
|
|
|
|
/// operation might introduce call nodes that might need type legalization.
|
|
|
|
bool IsLegalizingCallArgs;
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
enum LegalizeAction {
|
2006-01-29 08:42:06 +00:00
|
|
|
Legal, // The target natively supports this operation.
|
|
|
|
Promote, // This operation should be executed in a larger type.
|
2006-05-24 17:04:05 +00:00
|
|
|
Expand // Try to expand this to other ops, otherwise use a libcall.
|
2005-01-07 07:47:09 +00:00
|
|
|
};
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
/// ValueTypeActions - This is a bitvector that contains two bits for each
|
|
|
|
/// value type, where the two bits correspond to the LegalizeAction enum.
|
|
|
|
/// This can be queried with "getTypeAction(VT)".
|
2006-01-29 08:42:06 +00:00
|
|
|
TargetLowering::ValueTypeActionImpl ValueTypeActions;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
/// LegalizedNodes - For nodes that are of legal width, and that have more
|
|
|
|
/// than one use, this map indicates what regularized operand to use. This
|
|
|
|
/// allows us to avoid legalizing the same thing more than once.
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, SDValue> LegalizedNodes;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
/// PromotedNodes - For nodes that are below legal width, and that have more
|
|
|
|
/// than one use, this map indicates what promoted value to use. This allows
|
|
|
|
/// us to avoid promoting the same thing more than once.
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, SDValue> PromotedNodes;
|
2005-01-15 05:21:40 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// ExpandedNodes - For nodes that need to be expanded this map indicates
|
2008-10-30 08:01:45 +00:00
|
|
|
/// which operands are the expanded version of the input. This allows
|
2006-03-18 01:44:44 +00:00
|
|
|
/// us to avoid expanding the same node more than once.
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, std::pair<SDValue, SDValue> > ExpandedNodes;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// SplitNodes - For vector nodes that need to be split, this map indicates
|
2008-10-30 08:01:45 +00:00
|
|
|
/// which operands are the split version of the input. This allows us
|
2006-03-18 01:44:44 +00:00
|
|
|
/// to avoid splitting the same node more than once.
|
2008-07-27 21:46:04 +00:00
|
|
|
std::map<SDValue, std::pair<SDValue, SDValue> > SplitNodes;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ScalarizedNodes - For nodes that need to be converted from vector types to
|
|
|
|
/// scalar types, this contains the mapping of ones we have already
|
2006-03-18 01:44:44 +00:00
|
|
|
/// processed to the result.
|
2008-07-27 21:46:04 +00:00
|
|
|
std::map<SDValue, SDValue> ScalarizedNodes;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-11-06 05:31:54 +00:00
|
|
|
/// WidenNodes - For nodes that need to be widened from one vector type to
|
|
|
|
/// another, this contains the mapping of those that we have already widen.
|
|
|
|
/// This allows us to avoid widening more than once.
|
2008-10-30 08:01:45 +00:00
|
|
|
std::map<SDValue, SDValue> WidenNodes;
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
void AddLegalizedOperand(SDValue From, SDValue To) {
|
2005-12-20 00:53:54 +00:00
|
|
|
LegalizedNodes.insert(std::make_pair(From, To));
|
|
|
|
// If someone requests legalization of the new node, return itself.
|
|
|
|
if (From != To)
|
|
|
|
LegalizedNodes.insert(std::make_pair(To, To));
|
2005-01-07 22:28:47 +00:00
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
void AddPromotedOperand(SDValue From, SDValue To) {
|
2008-07-07 17:46:23 +00:00
|
|
|
bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second;
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(isNew && "Got into the map somehow?");
|
2008-11-24 07:09:49 +00:00
|
|
|
isNew = isNew;
|
2005-12-20 00:53:54 +00:00
|
|
|
// If someone requests legalization of the new node, return itself.
|
|
|
|
LegalizedNodes.insert(std::make_pair(To, To));
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
2008-11-06 05:31:54 +00:00
|
|
|
void AddWidenedOperand(SDValue From, SDValue To) {
|
2008-10-30 08:01:45 +00:00
|
|
|
bool isNew = WidenNodes.insert(std::make_pair(From, To)).second;
|
|
|
|
assert(isNew && "Got into the map somehow?");
|
2008-11-24 07:09:49 +00:00
|
|
|
isNew = isNew;
|
2008-10-30 08:01:45 +00:00
|
|
|
// If someone requests legalization of the new node, return itself.
|
|
|
|
LegalizedNodes.insert(std::make_pair(To, To));
|
|
|
|
}
|
2005-01-07 22:28:47 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
public:
|
2009-02-24 02:35:30 +00:00
|
|
|
explicit SelectionDAGLegalize(SelectionDAG &DAG, bool TypesNeedLegalizing,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level ol);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
/// getTypeAction - Return how we should legalize values of this type, either
|
|
|
|
/// it is already legal or we need to expand it into multiple registers of
|
|
|
|
/// smaller integer type, or we need to promote it to a larger type.
|
2008-06-06 12:08:01 +00:00
|
|
|
LegalizeAction getTypeAction(MVT VT) const {
|
2006-01-29 08:42:06 +00:00
|
|
|
return (LegalizeAction)ValueTypeActions.getTypeAction(VT);
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isTypeLegal - Return true if this type is legal on this target.
|
|
|
|
///
|
2008-06-06 12:08:01 +00:00
|
|
|
bool isTypeLegal(MVT VT) const {
|
2005-01-07 07:47:09 +00:00
|
|
|
return getTypeAction(VT) == Legal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegalizeDAG();
|
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
private:
|
2007-06-25 16:23:39 +00:00
|
|
|
/// HandleOp - Legalize, Promote, or Expand the specified operand as
|
2006-03-18 01:44:44 +00:00
|
|
|
/// appropriate for its type.
|
2008-07-27 21:46:04 +00:00
|
|
|
void HandleOp(SDValue Op);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// LegalizeOp - We know that the specified value has a legal type.
|
|
|
|
/// Recursively ensure that the operands have legal types, then return the
|
|
|
|
/// result.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LegalizeOp(SDValue O);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
/// UnrollVectorOp - We know that the given vector has a legal type, however
|
|
|
|
/// the operation it performs is not legal and is an operation that we have
|
|
|
|
/// no way of lowering. "Unroll" the vector, splitting out the scalars and
|
|
|
|
/// operating on each element individually.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue UnrollVectorOp(SDValue O);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-04-25 18:07:40 +00:00
|
|
|
/// PerformInsertVectorEltInMemory - Some target cannot handle a variable
|
|
|
|
/// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it
|
|
|
|
/// is necessary to spill the vector being inserted into to memory, perform
|
|
|
|
/// the insert there, and then read the result back.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val,
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Idx, DebugLoc dl);
|
2007-10-11 23:57:53 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// PromoteOp - Given an operation that produces a value in an invalid type,
|
|
|
|
/// promote it to compute the value into a larger type. The produced value
|
|
|
|
/// will have the correct bits for the low portion of the register, but no
|
|
|
|
/// guarantee is made about the top bits: it may be zero, sign-extended, or
|
|
|
|
/// garbage.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue PromoteOp(SDValue O);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
/// ExpandOp - Expand the specified SDValue into its two component pieces
|
2006-03-18 01:44:44 +00:00
|
|
|
/// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this,
|
2008-10-01 15:07:49 +00:00
|
|
|
/// the LegalizedNodes map is filled in for any results that are not expanded,
|
2006-03-18 01:44:44 +00:00
|
|
|
/// the ExpandedNodes map is filled in for any results that are expanded, and
|
|
|
|
/// the Lo/Hi values are returned. This applies to integer types and Vector
|
|
|
|
/// types.
|
2008-07-27 21:46:04 +00:00
|
|
|
void ExpandOp(SDValue O, SDValue &Lo, SDValue &Hi);
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
/// WidenVectorOp - Widen a vector operation to a wider type given by WidenVT
|
2008-11-06 05:31:54 +00:00
|
|
|
/// (e.g., v3i32 to v4i32). The produced value will have the correct value
|
|
|
|
/// for the existing elements but no guarantee is made about the new elements
|
|
|
|
/// at the end of the vector: it may be zero, ones, or garbage. This is useful
|
|
|
|
/// when we have an instruction operating on an illegal vector type and we
|
|
|
|
/// want to widen it to do the computation on a legal wider vector type.
|
2008-10-30 08:01:45 +00:00
|
|
|
SDValue WidenVectorOp(SDValue Op, MVT WidenVT);
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// SplitVectorOp - Given an operand of vector type, break it down into
|
|
|
|
/// two smaller values.
|
2008-07-27 21:46:04 +00:00
|
|
|
void SplitVectorOp(SDValue O, SDValue &Lo, SDValue &Hi);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-27 14:06:22 +00:00
|
|
|
/// ScalarizeVectorOp - Given an operand of single-element vector type
|
|
|
|
/// (e.g. v1f32), convert it into the equivalent operation that returns a
|
|
|
|
/// scalar (e.g. f32) value.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ScalarizeVectorOp(SDValue O);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-11-06 05:31:54 +00:00
|
|
|
/// Useful 16 element vector type that is used to pass operands for widening.
|
2009-02-17 22:15:04 +00:00
|
|
|
typedef SmallVector<SDValue, 16> SDValueVector;
|
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
/// LoadWidenVectorOp - Load a vector for a wider type. Returns true if
|
|
|
|
/// the LdChain contains a single load and false if it contains a token
|
|
|
|
/// factor for multiple loads. It takes
|
|
|
|
/// Result: location to return the result
|
|
|
|
/// LdChain: location to return the load chain
|
|
|
|
/// Op: load operation to widen
|
|
|
|
/// NVT: widen vector result type we want for the load
|
2009-02-17 22:15:04 +00:00
|
|
|
bool LoadWidenVectorOp(SDValue& Result, SDValue& LdChain,
|
2008-10-30 08:01:45 +00:00
|
|
|
SDValue Op, MVT NVT);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
/// Helper genWidenVectorLoads - Helper function to generate a set of
|
|
|
|
/// loads to load a vector with a resulting wider type. It takes
|
|
|
|
/// LdChain: list of chains for the load we have generated
|
|
|
|
/// Chain: incoming chain for the ld vector
|
|
|
|
/// BasePtr: base pointer to load from
|
|
|
|
/// SV: memory disambiguation source value
|
|
|
|
/// SVOffset: memory disambiugation offset
|
|
|
|
/// Alignment: alignment of the memory
|
|
|
|
/// isVolatile: volatile load
|
2009-02-17 22:15:04 +00:00
|
|
|
/// LdWidth: width of memory that we want to load
|
2008-10-30 08:01:45 +00:00
|
|
|
/// ResType: the wider result result type for the resulting loaded vector
|
|
|
|
SDValue genWidenVectorLoads(SDValueVector& LdChain, SDValue Chain,
|
|
|
|
SDValue BasePtr, const Value *SV,
|
|
|
|
int SVOffset, unsigned Alignment,
|
|
|
|
bool isVolatile, unsigned LdWidth,
|
2009-02-02 22:49:46 +00:00
|
|
|
MVT ResType, DebugLoc dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
/// StoreWidenVectorOp - Stores a widen vector into non widen memory
|
|
|
|
/// location. It takes
|
|
|
|
/// ST: store node that we want to replace
|
|
|
|
/// Chain: incoming store chain
|
|
|
|
/// BasePtr: base address of where we want to store into
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue StoreWidenVectorOp(StoreSDNode *ST, SDValue Chain,
|
2008-10-30 08:01:45 +00:00
|
|
|
SDValue BasePtr);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
/// Helper genWidenVectorStores - Helper function to generate a set of
|
|
|
|
/// stores to store a widen vector into non widen memory
|
|
|
|
// It takes
|
|
|
|
// StChain: list of chains for the stores we have generated
|
|
|
|
// Chain: incoming chain for the ld vector
|
|
|
|
// BasePtr: base pointer to load from
|
|
|
|
// SV: memory disambiguation source value
|
|
|
|
// SVOffset: memory disambiugation offset
|
|
|
|
// Alignment: alignment of the memory
|
|
|
|
// isVolatile: volatile lod
|
2009-02-17 22:15:04 +00:00
|
|
|
// ValOp: value to store
|
|
|
|
// StWidth: width of memory that we want to store
|
2008-10-30 08:01:45 +00:00
|
|
|
void genWidenVectorStores(SDValueVector& StChain, SDValue Chain,
|
|
|
|
SDValue BasePtr, const Value *SV,
|
|
|
|
int SVOffset, unsigned Alignment,
|
|
|
|
bool isVolatile, SDValue ValOp,
|
2009-02-02 22:49:46 +00:00
|
|
|
unsigned StWidth, DebugLoc dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-04-29 05:20:52 +00:00
|
|
|
/// ShuffleWithNarrowerEltType - Return a vector shuffle operation which
|
|
|
|
/// performs the same shuffe in terms of order or result bytes, but on a type
|
|
|
|
/// whose vector element type is narrower than the original shuffle type.
|
|
|
|
/// e.g. <v4i32> <0, 1, 0, 1> -> v8i16 <0, 1, 2, 3, 0, 1, 2, 3>
|
|
|
|
SDValue ShuffleWithNarrowerEltType(MVT NVT, MVT VT, DebugLoc dl,
|
|
|
|
SDValue N1, SDValue N2,
|
|
|
|
SmallVectorImpl<int> &Mask) const;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest,
|
2007-02-04 00:27:56 +00:00
|
|
|
SmallPtrSet<SDNode*, 32> &NodesLeadingTo);
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
void LegalizeSetCCOperands(SDValue &LHS, SDValue &RHS, SDValue &CC,
|
|
|
|
DebugLoc dl);
|
|
|
|
void LegalizeSetCCCondCode(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC,
|
|
|
|
DebugLoc dl);
|
|
|
|
void LegalizeSetCC(MVT VT, SDValue &LHS, SDValue &RHS, SDValue &CC,
|
|
|
|
DebugLoc dl) {
|
|
|
|
LegalizeSetCCOperands(LHS, RHS, CC, dl);
|
|
|
|
LegalizeSetCCCondCode(VT, LHS, RHS, CC, dl);
|
2008-10-15 02:05:31 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned,
|
|
|
|
SDValue &Hi);
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source, DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue EmitStackConvert(SDValue SrcOp, MVT SlotVT, MVT DestVT, DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandBUILD_VECTOR(SDNode *Node);
|
|
|
|
SDValue ExpandSCALAR_TO_VECTOR(SDNode *Node);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy,
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Op, DebugLoc dl);
|
|
|
|
SDValue ExpandLegalINT_TO_FP(bool isSigned, SDValue LegalOp, MVT DestVT,
|
|
|
|
DebugLoc dl);
|
|
|
|
SDValue PromoteLegalINT_TO_FP(SDValue LegalOp, MVT DestVT, bool isSigned,
|
|
|
|
DebugLoc dl);
|
|
|
|
SDValue PromoteLegalFP_TO_INT(SDValue LegalOp, MVT DestVT, bool isSigned,
|
|
|
|
DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue ExpandBSWAP(SDValue Op, DebugLoc dl);
|
|
|
|
SDValue ExpandBitCount(unsigned Opc, SDValue Op, DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
bool ExpandShift(unsigned Opc, SDValue Op, SDValue Amt,
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue &Lo, SDValue &Hi, DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
void ExpandShiftParts(unsigned NodeOp, SDValue Op, SDValue Amt,
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue &Lo, SDValue &Hi, DebugLoc dl);
|
2008-07-27 21:46:04 +00:00
|
|
|
|
|
|
|
SDValue ExpandEXTRACT_SUBVECTOR(SDValue Op);
|
|
|
|
SDValue ExpandEXTRACT_VECTOR_ELT(SDValue Op);
|
2005-01-07 07:47:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-04-29 05:20:52 +00:00
|
|
|
/// ShuffleWithNarrowerEltType - Return a vector shuffle operation which
|
|
|
|
/// performs the same shuffe in terms of order or result bytes, but on a type
|
|
|
|
/// whose vector element type is narrower than the original shuffle type.
|
2009-04-27 18:41:29 +00:00
|
|
|
/// e.g. <v4i32> <0, 1, 0, 1> -> v8i16 <0, 1, 2, 3, 0, 1, 2, 3>
|
2009-04-29 05:20:52 +00:00
|
|
|
SDValue
|
|
|
|
SelectionDAGLegalize::ShuffleWithNarrowerEltType(MVT NVT, MVT VT, DebugLoc dl,
|
|
|
|
SDValue N1, SDValue N2,
|
2009-04-27 18:41:29 +00:00
|
|
|
SmallVectorImpl<int> &Mask) const {
|
|
|
|
MVT EltVT = NVT.getVectorElementType();
|
2009-04-29 05:20:52 +00:00
|
|
|
unsigned NumMaskElts = VT.getVectorNumElements();
|
|
|
|
unsigned NumDestElts = NVT.getVectorNumElements();
|
2009-04-27 18:41:29 +00:00
|
|
|
unsigned NumEltsGrowth = NumDestElts / NumMaskElts;
|
|
|
|
|
|
|
|
assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!");
|
|
|
|
|
|
|
|
if (NumEltsGrowth == 1)
|
|
|
|
return DAG.getVectorShuffle(NVT, dl, N1, N2, &Mask[0]);
|
|
|
|
|
|
|
|
SmallVector<int, 8> NewMask;
|
2009-04-29 05:20:52 +00:00
|
|
|
for (unsigned i = 0; i != NumMaskElts; ++i) {
|
2009-04-27 18:41:29 +00:00
|
|
|
int Idx = Mask[i];
|
|
|
|
for (unsigned j = 0; j != NumEltsGrowth; ++j) {
|
|
|
|
if (Idx < 0)
|
|
|
|
NewMask.push_back(-1);
|
|
|
|
else
|
|
|
|
NewMask.push_back(Idx * NumEltsGrowth + j);
|
2006-04-04 17:23:26 +00:00
|
|
|
}
|
2009-04-24 12:40:33 +00:00
|
|
|
}
|
2009-04-29 05:20:52 +00:00
|
|
|
assert(NewMask.size() == NumDestElts && "Non-integer NumEltsGrowth?");
|
2009-04-27 18:41:29 +00:00
|
|
|
assert(TLI.isShuffleMaskLegal(NewMask, NVT) && "Shuffle not legal?");
|
|
|
|
return DAG.getVectorShuffle(NVT, dl, N1, N2, &NewMask[0]);
|
2006-04-04 17:23:26 +00:00
|
|
|
}
|
|
|
|
|
2009-02-24 02:35:30 +00:00
|
|
|
SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag,
|
2009-04-29 23:29:43 +00:00
|
|
|
bool types, CodeGenOpt::Level ol)
|
2009-04-29 00:15:41 +00:00
|
|
|
: TLI(dag.getTargetLoweringInfo()), DAG(dag), OptLevel(ol),
|
|
|
|
TypesNeedLegalizing(types), ValueTypeActions(TLI.getValueTypeActions()) {
|
2005-11-29 05:45:29 +00:00
|
|
|
assert(MVT::LAST_VALUETYPE <= 32 &&
|
2005-01-07 07:47:09 +00:00
|
|
|
"Too many value types for ValueTypeActions to hold!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionDAGLegalize::LegalizeDAG() {
|
2006-02-13 09:18:02 +00:00
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
IsLegalizingCall = false;
|
2009-02-04 19:38:14 +00:00
|
|
|
IsLegalizingCallArgs = false;
|
|
|
|
|
2005-10-02 17:49:46 +00:00
|
|
|
// The legalize process is inherently a bottom-up recursive process (users
|
|
|
|
// legalize their uses before themselves). Given infinite stack space, we
|
|
|
|
// could just start legalizing on the root and traverse the whole graph. In
|
|
|
|
// practice however, this causes us to run out of stack space on large basic
|
2005-10-06 01:20:27 +00:00
|
|
|
// blocks. To avoid this problem, compute an ordering of the nodes where each
|
|
|
|
// node is only legalized after all of its operands are legalized.
|
2008-09-30 18:30:35 +00:00
|
|
|
DAG.AssignTopologicalOrder();
|
|
|
|
for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
|
|
|
|
E = prior(DAG.allnodes_end()); I != next(E); ++I)
|
|
|
|
HandleOp(SDValue(I, 0));
|
2005-10-06 01:20:27 +00:00
|
|
|
|
|
|
|
// Finally, it's possible the root changed. Get the new root.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue OldRoot = DAG.getRoot();
|
2005-10-06 01:20:27 +00:00
|
|
|
assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
|
|
|
|
DAG.setRoot(LegalizedNodes[OldRoot]);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
ExpandedNodes.clear();
|
|
|
|
LegalizedNodes.clear();
|
2005-01-16 01:11:45 +00:00
|
|
|
PromotedNodes.clear();
|
2006-03-18 01:44:44 +00:00
|
|
|
SplitNodes.clear();
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizedNodes.clear();
|
2008-10-30 08:01:45 +00:00
|
|
|
WidenNodes.clear();
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
// Remove dead nodes now.
|
2006-08-04 17:45:20 +00:00
|
|
|
DAG.RemoveDeadNodes();
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
/// FindCallEndFromCallStart - Given a chained node that is part of a call
|
|
|
|
/// sequence, find the CALLSEQ_END node that terminates the call sequence.
|
|
|
|
static SDNode *FindCallEndFromCallStart(SDNode *Node) {
|
|
|
|
if (Node->getOpcode() == ISD::CALLSEQ_END)
|
|
|
|
return Node;
|
|
|
|
if (Node->use_empty())
|
|
|
|
return 0; // No CallSeqEnd
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// The chain is usually at the end.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue TheChain(Node, Node->getNumValues()-1);
|
2006-02-13 09:18:02 +00:00
|
|
|
if (TheChain.getValueType() != MVT::Other) {
|
|
|
|
// Sometimes it's at the beginning.
|
2008-07-27 21:46:04 +00:00
|
|
|
TheChain = SDValue(Node, 0);
|
2006-02-13 09:18:02 +00:00
|
|
|
if (TheChain.getValueType() != MVT::Other) {
|
|
|
|
// Otherwise, hunt for it.
|
|
|
|
for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i)
|
|
|
|
if (Node->getValueType(i) == MVT::Other) {
|
2008-07-27 21:46:04 +00:00
|
|
|
TheChain = SDValue(Node, i);
|
2006-02-13 09:18:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// Otherwise, we walked into a node without a chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
if (TheChain.getValueType() != MVT::Other)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
for (SDNode::use_iterator UI = Node->use_begin(),
|
|
|
|
E = Node->use_end(); UI != E; ++UI) {
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Make sure to only follow users of our token chain.
|
2008-07-27 20:43:25 +00:00
|
|
|
SDNode *User = *UI;
|
2006-02-13 09:18:02 +00:00
|
|
|
for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i)
|
|
|
|
if (User->getOperand(i) == TheChain)
|
|
|
|
if (SDNode *Result = FindCallEndFromCallStart(User))
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
/// FindCallStartFromCallEnd - Given a chained node that is part of a call
|
2006-02-13 09:18:02 +00:00
|
|
|
/// sequence, find the CALLSEQ_START node that initiates the call sequence.
|
|
|
|
static SDNode *FindCallStartFromCallEnd(SDNode *Node) {
|
|
|
|
assert(Node && "Didn't find callseq_start for a call??");
|
|
|
|
if (Node->getOpcode() == ISD::CALLSEQ_START) return Node;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
assert(Node->getOperand(0).getValueType() == MVT::Other &&
|
|
|
|
"Node doesn't have a token chain argument!");
|
2008-08-28 21:40:38 +00:00
|
|
|
return FindCallStartFromCallEnd(Node->getOperand(0).getNode());
|
2006-02-13 09:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to
|
2009-02-17 22:15:04 +00:00
|
|
|
/// see if any uses can reach Dest. If no dest operands can get to dest,
|
2006-02-13 09:18:02 +00:00
|
|
|
/// legalize them, legalize ourself, and return false, otherwise, return true.
|
2006-07-26 23:55:56 +00:00
|
|
|
///
|
|
|
|
/// Keep track of the nodes we fine that actually do lead to Dest in
|
|
|
|
/// NodesLeadingTo. This avoids retraversing them exponential number of times.
|
|
|
|
///
|
|
|
|
bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest,
|
2007-02-04 00:27:56 +00:00
|
|
|
SmallPtrSet<SDNode*, 32> &NodesLeadingTo) {
|
2006-02-13 09:18:02 +00:00
|
|
|
if (N == Dest) return true; // N certainly leads to Dest :)
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
// If we've already processed this node and it does lead to Dest, there is no
|
|
|
|
// need to reprocess it.
|
|
|
|
if (NodesLeadingTo.count(N)) return true;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// If the first result of this node has been already legalized, then it cannot
|
|
|
|
// reach N.
|
|
|
|
switch (getTypeAction(N->getValueType(0))) {
|
2009-02-17 22:15:04 +00:00
|
|
|
case Legal:
|
2008-07-27 21:46:04 +00:00
|
|
|
if (LegalizedNodes.count(SDValue(N, 0))) return false;
|
2006-02-13 09:18:02 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
2008-07-27 21:46:04 +00:00
|
|
|
if (PromotedNodes.count(SDValue(N, 0))) return false;
|
2006-02-13 09:18:02 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
2008-07-27 21:46:04 +00:00
|
|
|
if (ExpandedNodes.count(SDValue(N, 0))) return false;
|
2006-02-13 09:18:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Okay, this node has not already been legalized. Check and legalize all
|
|
|
|
// operands. If none lead to Dest, then we can legalize this node.
|
|
|
|
bool OperandsLeadToDest = false;
|
|
|
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
|
|
|
|
OperandsLeadToDest |= // If an operand leads to Dest, so do we.
|
2008-08-28 21:40:38 +00:00
|
|
|
LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo);
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
if (OperandsLeadToDest) {
|
|
|
|
NodesLeadingTo.insert(N);
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Okay, this node looks safe, legalize it and return false.
|
2008-07-27 21:46:04 +00:00
|
|
|
HandleOp(SDValue(N, 0));
|
2006-02-13 09:18:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
/// HandleOp - Legalize, Promote, Widen, or Expand the specified operand as
|
2006-03-18 01:44:44 +00:00
|
|
|
/// appropriate for its type.
|
2008-07-27 21:46:04 +00:00
|
|
|
void SelectionDAGLegalize::HandleOp(SDValue Op) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2008-12-14 09:43:15 +00:00
|
|
|
// If the type legalizer was run then we should never see any illegal result
|
|
|
|
// types here except for target constants (the type legalizer does not touch
|
2008-12-18 20:03:17 +00:00
|
|
|
// those) or for build vector used as a mask for a vector shuffle.
|
2008-12-14 09:43:15 +00:00
|
|
|
assert((TypesNeedLegalizing || getTypeAction(VT) == Legal ||
|
2009-04-27 19:33:03 +00:00
|
|
|
IsLegalizingCallArgs || Op.getOpcode() == ISD::TargetConstant) &&
|
2008-12-14 09:43:15 +00:00
|
|
|
"Illegal type introduced after type legalization?");
|
2007-06-25 16:23:39 +00:00
|
|
|
switch (getTypeAction(VT)) {
|
2006-03-18 01:44:44 +00:00
|
|
|
default: assert(0 && "Bad type action!");
|
2007-06-25 16:23:39 +00:00
|
|
|
case Legal: (void)LegalizeOp(Op); break;
|
2008-10-30 08:01:45 +00:00
|
|
|
case Promote:
|
|
|
|
if (!VT.isVector()) {
|
|
|
|
(void)PromoteOp(Op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// See if we can widen otherwise use Expand to either scalarize or split
|
|
|
|
MVT WidenVT = TLI.getWidenVectorType(VT);
|
|
|
|
if (WidenVT != MVT::Other) {
|
|
|
|
(void) WidenVectorOp(Op, WidenVT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// else fall thru to expand since we can't widen the vector
|
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
case Expand:
|
2008-06-06 12:08:01 +00:00
|
|
|
if (!VT.isVector()) {
|
2007-06-25 16:23:39 +00:00
|
|
|
// If this is an illegal scalar, expand it into its two component
|
|
|
|
// pieces.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue X, Y;
|
2007-08-25 01:00:22 +00:00
|
|
|
if (Op.getOpcode() == ISD::TargetConstant)
|
|
|
|
break; // Allow illegal target nodes.
|
2006-03-18 01:44:44 +00:00
|
|
|
ExpandOp(Op, X, Y);
|
2008-06-06 12:08:01 +00:00
|
|
|
} else if (VT.getVectorNumElements() == 1) {
|
2007-06-25 16:23:39 +00:00
|
|
|
// If this is an illegal single element vector, convert it to a
|
|
|
|
// scalar operation.
|
|
|
|
(void)ScalarizeVectorOp(Op);
|
2006-03-18 01:44:44 +00:00
|
|
|
} else {
|
2008-10-30 08:01:45 +00:00
|
|
|
// This is an illegal multiple element vector.
|
2007-06-25 16:23:39 +00:00
|
|
|
// Split it in half and legalize both parts.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue X, Y;
|
2007-06-25 16:23:39 +00:00
|
|
|
SplitVectorOp(Op, X, Y);
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2006-12-13 20:57:08 +00:00
|
|
|
/// ExpandConstantFP - Expands the ConstantFP node to an integer constant or
|
|
|
|
/// a load from the constant pool.
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
|
2009-01-15 16:43:02 +00:00
|
|
|
SelectionDAG &DAG, const TargetLowering &TLI) {
|
2006-12-12 21:32:44 +00:00
|
|
|
bool Extend = false;
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = CFP->getDebugLoc();
|
2006-12-12 21:32:44 +00:00
|
|
|
|
|
|
|
// If a FP immediate is precise when represented as a float and if the
|
|
|
|
// target can do an extending load from float to double, we put it into
|
|
|
|
// the constant pool as a float, even if it's is statically typed as a
|
2008-03-05 06:46:58 +00:00
|
|
|
// double. This shrinks FP constants and canonicalizes them for targets where
|
|
|
|
// an FP extending load is the same cost as a normal load (such as on the x87
|
|
|
|
// fp stack or PPC FP unit).
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = CFP->getValueType(0);
|
2008-09-12 18:08:03 +00:00
|
|
|
ConstantFP *LLVMC = const_cast<ConstantFP*>(CFP->getConstantFPValue());
|
2006-12-13 20:57:08 +00:00
|
|
|
if (!UseCP) {
|
2009-03-08 01:47:41 +00:00
|
|
|
assert((VT == MVT::f64 || VT == MVT::f32) && "Invalid type expansion");
|
2008-10-09 18:53:47 +00:00
|
|
|
return DAG.getConstant(LLVMC->getValueAPF().bitcastToAPInt(),
|
2008-03-04 08:05:30 +00:00
|
|
|
(VT == MVT::f64) ? MVT::i64 : MVT::i32);
|
2006-12-12 22:19:28 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OrigVT = VT;
|
|
|
|
MVT SVT = VT;
|
2008-03-04 08:05:30 +00:00
|
|
|
while (SVT != MVT::f32) {
|
2008-06-06 12:08:01 +00:00
|
|
|
SVT = (MVT::SimpleValueType)(SVT.getSimpleVT() - 1);
|
2008-03-04 08:05:30 +00:00
|
|
|
if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) &&
|
|
|
|
// Only do this if the target has a native EXTLOAD instruction from
|
|
|
|
// smaller type.
|
2008-10-14 21:26:46 +00:00
|
|
|
TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) &&
|
2008-03-05 06:46:58 +00:00
|
|
|
TLI.ShouldShrinkFPConstant(OrigVT)) {
|
2008-06-06 12:08:01 +00:00
|
|
|
const Type *SType = SVT.getTypeForMVT();
|
2008-03-04 08:05:30 +00:00
|
|
|
LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
|
|
|
|
VT = SVT;
|
|
|
|
Extend = true;
|
|
|
|
}
|
2006-12-12 21:32:44 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
2008-03-04 08:05:30 +00:00
|
|
|
if (Extend)
|
2009-02-04 20:06:27 +00:00
|
|
|
return DAG.getExtLoad(ISD::EXTLOAD, dl,
|
2009-02-04 02:34:38 +00:00
|
|
|
OrigVT, DAG.getEntryNode(),
|
2008-02-07 18:41:25 +00:00
|
|
|
CPIdx, PseudoSourceValue::getConstantPool(),
|
2008-09-16 22:05:41 +00:00
|
|
|
0, VT, false, Alignment);
|
2009-02-04 20:06:27 +00:00
|
|
|
return DAG.getLoad(OrigVT, dl, DAG.getEntryNode(), CPIdx,
|
2008-09-16 22:05:41 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0, false, Alignment);
|
2006-12-12 21:32:44 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2007-01-04 21:56:39 +00:00
|
|
|
/// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise
|
|
|
|
/// operations.
|
|
|
|
static
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT NVT,
|
2009-01-15 16:43:02 +00:00
|
|
|
SelectionDAG &DAG,
|
|
|
|
const TargetLowering &TLI) {
|
2009-02-02 20:41:04 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
MVT SrcVT = Node->getOperand(1).getValueType();
|
2007-06-25 16:23:39 +00:00
|
|
|
assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) &&
|
|
|
|
"fcopysign expansion only supported for f32 and f64");
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32;
|
2007-01-05 21:31:51 +00:00
|
|
|
|
2007-01-04 21:56:39 +00:00
|
|
|
// First get the sign bit of second operand.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Mask1 = (SrcVT == MVT::f64)
|
2007-01-04 21:56:39 +00:00
|
|
|
? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT);
|
2009-02-02 20:41:04 +00:00
|
|
|
Mask1 = DAG.getNode(ISD::BIT_CONVERT, dl, SrcNVT, Mask1);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue SignBit= DAG.getNode(ISD::BIT_CONVERT, dl, SrcNVT,
|
2009-02-02 20:41:04 +00:00
|
|
|
Node->getOperand(1));
|
|
|
|
SignBit = DAG.getNode(ISD::AND, dl, SrcNVT, SignBit, Mask1);
|
2007-01-04 21:56:39 +00:00
|
|
|
// Shift right or sign-extend it if the two operands have different types.
|
2008-06-06 12:08:01 +00:00
|
|
|
int SizeDiff = SrcNVT.getSizeInBits() - NVT.getSizeInBits();
|
2007-01-04 21:56:39 +00:00
|
|
|
if (SizeDiff > 0) {
|
2009-02-02 20:41:04 +00:00
|
|
|
SignBit = DAG.getNode(ISD::SRL, dl, SrcNVT, SignBit,
|
2007-01-04 21:56:39 +00:00
|
|
|
DAG.getConstant(SizeDiff, TLI.getShiftAmountTy()));
|
2009-02-02 20:41:04 +00:00
|
|
|
SignBit = DAG.getNode(ISD::TRUNCATE, dl, NVT, SignBit);
|
2008-07-10 23:46:13 +00:00
|
|
|
} else if (SizeDiff < 0) {
|
2009-02-02 20:41:04 +00:00
|
|
|
SignBit = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, SignBit);
|
|
|
|
SignBit = DAG.getNode(ISD::SHL, dl, NVT, SignBit,
|
2008-07-10 23:46:13 +00:00
|
|
|
DAG.getConstant(-SizeDiff, TLI.getShiftAmountTy()));
|
|
|
|
}
|
2007-01-05 21:31:51 +00:00
|
|
|
|
|
|
|
// Clear the sign bit of first operand.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Mask2 = (VT == MVT::f64)
|
2007-01-05 21:31:51 +00:00
|
|
|
? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT);
|
2009-02-02 20:41:04 +00:00
|
|
|
Mask2 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Mask2);
|
|
|
|
SDValue Result = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::AND, dl, NVT, Result, Mask2);
|
2007-01-05 21:31:51 +00:00
|
|
|
|
|
|
|
// Or the value with the sign bit.
|
2009-02-02 20:41:04 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, dl, NVT, Result, SignBit);
|
2007-01-04 21:56:39 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2007-08-01 19:34:21 +00:00
|
|
|
/// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores.
|
|
|
|
static
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG,
|
2009-01-15 16:43:02 +00:00
|
|
|
const TargetLowering &TLI) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Chain = ST->getChain();
|
|
|
|
SDValue Ptr = ST->getBasePtr();
|
|
|
|
SDValue Val = ST->getValue();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Val.getValueType();
|
2007-09-08 19:29:23 +00:00
|
|
|
int Alignment = ST->getAlignment();
|
|
|
|
int SVOffset = ST->getSrcValueOffset();
|
2009-02-02 20:41:04 +00:00
|
|
|
DebugLoc dl = ST->getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
if (ST->getMemoryVT().isFloatingPoint() ||
|
|
|
|
ST->getMemoryVT().isVector()) {
|
2008-12-12 21:47:02 +00:00
|
|
|
MVT intVT = MVT::getIntegerVT(VT.getSizeInBits());
|
|
|
|
if (TLI.isTypeLegal(intVT)) {
|
|
|
|
// Expand to a bitconvert of the value to the integer type of the
|
|
|
|
// same size, then a (misaligned) int store.
|
|
|
|
// FIXME: Does not handle truncating floating point stores!
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Result = DAG.getNode(ISD::BIT_CONVERT, dl, intVT, Val);
|
|
|
|
return DAG.getStore(Chain, dl, Result, Ptr, ST->getSrcValue(),
|
2008-12-12 21:47:02 +00:00
|
|
|
SVOffset, ST->isVolatile(), Alignment);
|
|
|
|
} else {
|
|
|
|
// Do a (aligned) store to a stack slot, then copy from the stack slot
|
|
|
|
// to the final destination using (unaligned) integer loads and stores.
|
|
|
|
MVT StoredVT = ST->getMemoryVT();
|
|
|
|
MVT RegVT =
|
|
|
|
TLI.getRegisterType(MVT::getIntegerVT(StoredVT.getSizeInBits()));
|
|
|
|
unsigned StoredBytes = StoredVT.getSizeInBits() / 8;
|
|
|
|
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
|
|
|
unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes;
|
|
|
|
|
2008-12-13 07:18:38 +00:00
|
|
|
// Make sure the stack slot is also aligned for the register type.
|
|
|
|
SDValue StackPtr = DAG.CreateStackTemporary(StoredVT, RegVT);
|
|
|
|
|
|
|
|
// Perform the original store, only redirected to the stack slot.
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue Store = DAG.getTruncStore(Chain, dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
Val, StackPtr, NULL, 0, StoredVT);
|
2008-12-12 21:47:02 +00:00
|
|
|
SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy());
|
|
|
|
SmallVector<SDValue, 8> Stores;
|
|
|
|
unsigned Offset = 0;
|
|
|
|
|
|
|
|
// Do all but one copies using the full register width.
|
|
|
|
for (unsigned i = 1; i < NumRegs; i++) {
|
|
|
|
// Load one integer register's worth from the stack slot.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Load = DAG.getLoad(RegVT, dl, Store, StackPtr, NULL, 0);
|
2008-12-12 21:47:02 +00:00
|
|
|
// Store it to the final location. Remember the store.
|
2009-02-02 20:41:04 +00:00
|
|
|
Stores.push_back(DAG.getStore(Load.getValue(1), dl, Load, Ptr,
|
2008-12-12 21:47:02 +00:00
|
|
|
ST->getSrcValue(), SVOffset + Offset,
|
|
|
|
ST->isVolatile(),
|
|
|
|
MinAlign(ST->getAlignment(), Offset)));
|
|
|
|
// Increment the pointers.
|
|
|
|
Offset += RegBytes;
|
2009-02-02 20:41:04 +00:00
|
|
|
StackPtr = DAG.getNode(ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
|
2008-12-12 21:47:02 +00:00
|
|
|
Increment);
|
2009-02-02 20:41:04 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, Increment);
|
2008-12-12 21:47:02 +00:00
|
|
|
}
|
|
|
|
|
2008-12-13 07:18:38 +00:00
|
|
|
// The last store may be partial. Do a truncating store. On big-endian
|
|
|
|
// machines this requires an extending load from the stack slot to ensure
|
|
|
|
// that the bits are in the right place.
|
|
|
|
MVT MemVT = MVT::getIntegerVT(8 * (StoredBytes - Offset));
|
|
|
|
|
|
|
|
// Load from the stack slot.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, RegVT, Store, StackPtr,
|
2008-12-13 07:18:38 +00:00
|
|
|
NULL, 0, MemVT);
|
2008-12-12 21:47:02 +00:00
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
Stores.push_back(DAG.getTruncStore(Load.getValue(1), dl, Load, Ptr,
|
2008-12-12 21:47:02 +00:00
|
|
|
ST->getSrcValue(), SVOffset + Offset,
|
2008-12-13 07:18:38 +00:00
|
|
|
MemVT, ST->isVolatile(),
|
2008-12-12 21:47:02 +00:00
|
|
|
MinAlign(ST->getAlignment(), Offset)));
|
|
|
|
// The order of the stores doesn't matter - say it with a TokenFactor.
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Stores[0],
|
2008-12-12 21:47:02 +00:00
|
|
|
Stores.size());
|
|
|
|
}
|
2007-09-08 19:29:23 +00:00
|
|
|
}
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(ST->getMemoryVT().isInteger() &&
|
|
|
|
!ST->getMemoryVT().isVector() &&
|
2007-09-08 19:29:23 +00:00
|
|
|
"Unaligned store of unknown type.");
|
2007-08-01 19:34:21 +00:00
|
|
|
// Get the half-size VT
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewStoredVT =
|
|
|
|
(MVT::SimpleValueType)(ST->getMemoryVT().getSimpleVT() - 1);
|
|
|
|
int NumBits = NewStoredVT.getSizeInBits();
|
2007-08-01 19:34:21 +00:00
|
|
|
int IncrementSize = NumBits / 8;
|
|
|
|
|
|
|
|
// Divide the stored value in two parts.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy());
|
|
|
|
SDValue Lo = Val;
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Hi = DAG.getNode(ISD::SRL, dl, VT, Val, ShiftAmount);
|
2007-08-01 19:34:21 +00:00
|
|
|
|
|
|
|
// Store the two parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Store1, Store2;
|
2009-02-02 20:41:04 +00:00
|
|
|
Store1 = DAG.getTruncStore(Chain, dl, TLI.isLittleEndian()?Lo:Hi, Ptr,
|
2007-08-01 19:34:21 +00:00
|
|
|
ST->getSrcValue(), SVOffset, NewStoredVT,
|
|
|
|
ST->isVolatile(), Alignment);
|
2009-02-02 20:41:04 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
|
2007-08-01 19:34:21 +00:00
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2009-02-02 20:41:04 +00:00
|
|
|
Store2 = DAG.getTruncStore(Chain, dl, TLI.isLittleEndian()?Hi:Lo, Ptr,
|
2007-08-01 19:34:21 +00:00
|
|
|
ST->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
NewStoredVT, ST->isVolatile(), Alignment);
|
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Store1, Store2);
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads.
|
|
|
|
static
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG,
|
2009-01-15 16:58:17 +00:00
|
|
|
const TargetLowering &TLI) {
|
2007-08-01 19:34:21 +00:00
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Chain = LD->getChain();
|
|
|
|
SDValue Ptr = LD->getBasePtr();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = LD->getValueType(0);
|
|
|
|
MVT LoadedVT = LD->getMemoryVT();
|
2009-02-02 20:41:04 +00:00
|
|
|
DebugLoc dl = LD->getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isFloatingPoint() || VT.isVector()) {
|
2008-12-12 21:47:02 +00:00
|
|
|
MVT intVT = MVT::getIntegerVT(LoadedVT.getSizeInBits());
|
|
|
|
if (TLI.isTypeLegal(intVT)) {
|
|
|
|
// Expand to a (misaligned) integer load of the same size,
|
|
|
|
// then bitconvert to floating point or vector.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue newLoad = DAG.getLoad(intVT, dl, Chain, Ptr, LD->getSrcValue(),
|
2008-12-12 21:47:02 +00:00
|
|
|
SVOffset, LD->isVolatile(),
|
2007-09-08 19:29:23 +00:00
|
|
|
LD->getAlignment());
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Result = DAG.getNode(ISD::BIT_CONVERT, dl, LoadedVT, newLoad);
|
2008-12-12 21:47:02 +00:00
|
|
|
if (VT.isFloatingPoint() && LoadedVT != VT)
|
2009-02-02 20:41:04 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, dl, VT, Result);
|
2007-09-08 19:29:23 +00:00
|
|
|
|
2008-12-12 21:47:02 +00:00
|
|
|
SDValue Ops[] = { Result, Chain };
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
2008-12-12 21:47:02 +00:00
|
|
|
} else {
|
|
|
|
// Copy the value to a (aligned) stack slot using (unaligned) integer
|
|
|
|
// loads and stores, then do a (aligned) load from the stack slot.
|
|
|
|
MVT RegVT = TLI.getRegisterType(intVT);
|
|
|
|
unsigned LoadedBytes = LoadedVT.getSizeInBits() / 8;
|
|
|
|
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
|
|
|
unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes;
|
|
|
|
|
2008-12-13 07:18:38 +00:00
|
|
|
// Make sure the stack slot is also aligned for the register type.
|
|
|
|
SDValue StackBase = DAG.CreateStackTemporary(LoadedVT, RegVT);
|
|
|
|
|
2008-12-12 21:47:02 +00:00
|
|
|
SDValue Increment = DAG.getConstant(RegBytes, TLI.getPointerTy());
|
|
|
|
SmallVector<SDValue, 8> Stores;
|
|
|
|
SDValue StackPtr = StackBase;
|
|
|
|
unsigned Offset = 0;
|
|
|
|
|
|
|
|
// Do all but one copies using the full register width.
|
|
|
|
for (unsigned i = 1; i < NumRegs; i++) {
|
|
|
|
// Load one integer register's worth from the original location.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Load = DAG.getLoad(RegVT, dl, Chain, Ptr, LD->getSrcValue(),
|
2008-12-12 21:47:02 +00:00
|
|
|
SVOffset + Offset, LD->isVolatile(),
|
|
|
|
MinAlign(LD->getAlignment(), Offset));
|
|
|
|
// Follow the load with a store to the stack slot. Remember the store.
|
2009-02-02 20:41:04 +00:00
|
|
|
Stores.push_back(DAG.getStore(Load.getValue(1), dl, Load, StackPtr,
|
2008-12-12 21:47:02 +00:00
|
|
|
NULL, 0));
|
|
|
|
// Increment the pointers.
|
|
|
|
Offset += RegBytes;
|
2009-02-02 20:41:04 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, Increment);
|
|
|
|
StackPtr = DAG.getNode(ISD::ADD, dl, StackPtr.getValueType(), StackPtr,
|
2008-12-12 21:47:02 +00:00
|
|
|
Increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last copy may be partial. Do an extending load.
|
2008-12-13 07:18:38 +00:00
|
|
|
MVT MemVT = MVT::getIntegerVT(8 * (LoadedBytes - Offset));
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, RegVT, Chain, Ptr,
|
2008-12-12 21:47:02 +00:00
|
|
|
LD->getSrcValue(), SVOffset + Offset,
|
2008-12-13 07:18:38 +00:00
|
|
|
MemVT, LD->isVolatile(),
|
2008-12-12 21:47:02 +00:00
|
|
|
MinAlign(LD->getAlignment(), Offset));
|
|
|
|
// Follow the load with a store to the stack slot. Remember the store.
|
2008-12-13 07:18:38 +00:00
|
|
|
// On big-endian machines this requires a truncating store to ensure
|
|
|
|
// that the bits end up in the right place.
|
2009-02-02 20:41:04 +00:00
|
|
|
Stores.push_back(DAG.getTruncStore(Load.getValue(1), dl, Load, StackPtr,
|
2008-12-13 07:18:38 +00:00
|
|
|
NULL, 0, MemVT));
|
2008-12-12 21:47:02 +00:00
|
|
|
|
|
|
|
// The order of the stores doesn't matter - say it with a TokenFactor.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &Stores[0],
|
2008-12-12 21:47:02 +00:00
|
|
|
Stores.size());
|
|
|
|
|
|
|
|
// Finally, perform the original load only redirected to the stack slot.
|
2009-02-02 20:41:04 +00:00
|
|
|
Load = DAG.getExtLoad(LD->getExtensionType(), dl, VT, TF, StackBase,
|
2008-12-12 21:47:02 +00:00
|
|
|
NULL, 0, LoadedVT);
|
|
|
|
|
|
|
|
// Callers expect a MERGE_VALUES node.
|
|
|
|
SDValue Ops[] = { Load, TF };
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
2008-12-12 21:47:02 +00:00
|
|
|
}
|
2007-09-08 19:29:23 +00:00
|
|
|
}
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(LoadedVT.isInteger() && !LoadedVT.isVector() &&
|
2007-11-19 21:38:03 +00:00
|
|
|
"Unaligned load of unsupported type.");
|
|
|
|
|
2008-02-27 22:36:00 +00:00
|
|
|
// Compute the new VT that is half the size of the old one. This is an
|
|
|
|
// integer MVT.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumBits = LoadedVT.getSizeInBits();
|
|
|
|
MVT NewLoadedVT;
|
|
|
|
NewLoadedVT = MVT::getIntegerVT(NumBits/2);
|
2007-11-19 21:38:03 +00:00
|
|
|
NumBits >>= 1;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-11-19 21:38:03 +00:00
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
unsigned IncrementSize = NumBits / 8;
|
2007-08-01 19:34:21 +00:00
|
|
|
ISD::LoadExtType HiExtType = LD->getExtensionType();
|
|
|
|
|
|
|
|
// If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD.
|
|
|
|
if (HiExtType == ISD::NON_EXTLOAD)
|
|
|
|
HiExtType = ISD::ZEXTLOAD;
|
|
|
|
|
|
|
|
// Load the value in two parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2007-08-01 19:34:21 +00:00
|
|
|
if (TLI.isLittleEndian()) {
|
2009-02-02 20:41:04 +00:00
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl, VT, Chain, Ptr, LD->getSrcValue(),
|
2007-08-01 19:34:21 +00:00
|
|
|
SVOffset, NewLoadedVT, LD->isVolatile(), Alignment);
|
2009-02-02 20:41:04 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
|
2007-08-01 19:34:21 +00:00
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
2009-02-02 20:41:04 +00:00
|
|
|
Hi = DAG.getExtLoad(HiExtType, dl, VT, Chain, Ptr, LD->getSrcValue(),
|
2007-08-01 19:34:21 +00:00
|
|
|
SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(),
|
2007-10-28 12:59:45 +00:00
|
|
|
MinAlign(Alignment, IncrementSize));
|
2007-08-01 19:34:21 +00:00
|
|
|
} else {
|
2009-02-02 20:41:04 +00:00
|
|
|
Hi = DAG.getExtLoad(HiExtType, dl, VT, Chain, Ptr, LD->getSrcValue(),
|
2009-04-10 18:48:47 +00:00
|
|
|
SVOffset, NewLoadedVT, LD->isVolatile(), Alignment);
|
2009-02-02 20:41:04 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
|
2007-08-01 19:34:21 +00:00
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
2009-02-02 20:41:04 +00:00
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl, VT, Chain, Ptr, LD->getSrcValue(),
|
2007-08-01 19:34:21 +00:00
|
|
|
SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(),
|
2007-10-28 12:59:45 +00:00
|
|
|
MinAlign(Alignment, IncrementSize));
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// aggregate the two parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy());
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Result = DAG.getNode(ISD::SHL, dl, VT, Hi, ShiftAmount);
|
|
|
|
Result = DAG.getNode(ISD::OR, dl, VT, Result, Lo);
|
2007-08-01 19:34:21 +00:00
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
|
2007-08-01 19:34:21 +00:00
|
|
|
Hi.getValue(1));
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[] = { Result, TF };
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
/// UnrollVectorOp - We know that the given vector has a legal type, however
|
|
|
|
/// the operation it performs is not legal and is an operation that we have
|
|
|
|
/// no way of lowering. "Unroll" the vector, splitting out the scalars and
|
|
|
|
/// operating on each element individually.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::UnrollVectorOp(SDValue Op) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2007-10-11 23:57:53 +00:00
|
|
|
assert(isTypeLegal(VT) &&
|
|
|
|
"Caller should expand or promote operands that are not legal!");
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Op.getNode()->getNumValues() == 1 &&
|
2007-10-11 23:57:53 +00:00
|
|
|
"Can't unroll a vector with multiple results!");
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NE = VT.getVectorNumElements();
|
|
|
|
MVT EltVT = VT.getVectorElementType();
|
2009-02-07 19:59:05 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-10-11 23:57:53 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Scalars;
|
|
|
|
SmallVector<SDValue, 4> Operands(Op.getNumOperands());
|
2007-10-11 23:57:53 +00:00
|
|
|
for (unsigned i = 0; i != NE; ++i) {
|
|
|
|
for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Operand = Op.getOperand(j);
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OperandVT = Operand.getValueType();
|
|
|
|
if (OperandVT.isVector()) {
|
2007-10-11 23:57:53 +00:00
|
|
|
// A vector operand; extract a single element.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OperandEltVT = OperandVT.getVectorElementType();
|
2009-02-02 20:41:04 +00:00
|
|
|
Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
|
2007-10-11 23:57:53 +00:00
|
|
|
OperandEltVT,
|
|
|
|
Operand,
|
|
|
|
DAG.getConstant(i, MVT::i32));
|
|
|
|
} else {
|
|
|
|
// A scalar operand; just use it as is.
|
|
|
|
Operands[j] = Operand;
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 05:46:39 +00:00
|
|
|
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default:
|
2009-02-02 20:41:04 +00:00
|
|
|
Scalars.push_back(DAG.getNode(Op.getOpcode(), dl, EltVT,
|
2008-12-09 05:46:39 +00:00
|
|
|
&Operands[0], Operands.size()));
|
|
|
|
break;
|
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRA:
|
|
|
|
case ISD::SRL:
|
2009-01-31 15:50:11 +00:00
|
|
|
case ISD::ROTL:
|
|
|
|
case ISD::ROTR:
|
2009-02-02 20:41:04 +00:00
|
|
|
Scalars.push_back(DAG.getNode(Op.getOpcode(), dl, EltVT, Operands[0],
|
2009-01-31 15:50:11 +00:00
|
|
|
DAG.getShiftAmountOperand(Operands[1])));
|
2008-12-09 05:46:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 23:57:53 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 22:49:59 +00:00
|
|
|
return DAG.getNode(ISD::BUILD_VECTOR, dl, VT, &Scalars[0], Scalars.size());
|
2007-10-11 23:57:53 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 10:28:30 +00:00
|
|
|
/// GetFPLibCall - Return the right libcall for the given floating point type.
|
2008-06-06 12:08:01 +00:00
|
|
|
static RTLIB::Libcall GetFPLibCall(MVT VT,
|
2008-01-10 10:28:30 +00:00
|
|
|
RTLIB::Libcall Call_F32,
|
|
|
|
RTLIB::Libcall Call_F64,
|
|
|
|
RTLIB::Libcall Call_F80,
|
|
|
|
RTLIB::Libcall Call_PPCF128) {
|
|
|
|
return
|
|
|
|
VT == MVT::f32 ? Call_F32 :
|
|
|
|
VT == MVT::f64 ? Call_F64 :
|
|
|
|
VT == MVT::f80 ? Call_F80 :
|
|
|
|
VT == MVT::ppcf128 ? Call_PPCF128 :
|
|
|
|
RTLIB::UNKNOWN_LIBCALL;
|
|
|
|
}
|
|
|
|
|
2008-04-25 18:07:40 +00:00
|
|
|
/// PerformInsertVectorEltInMemory - Some target cannot handle a variable
|
|
|
|
/// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it
|
|
|
|
/// is necessary to spill the vector being inserted into to memory, perform
|
|
|
|
/// the insert there, and then read the result back.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::
|
2009-02-02 20:41:04 +00:00
|
|
|
PerformInsertVectorEltInMemory(SDValue Vec, SDValue Val, SDValue Idx,
|
|
|
|
DebugLoc dl) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp1 = Vec;
|
|
|
|
SDValue Tmp2 = Val;
|
|
|
|
SDValue Tmp3 = Idx;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-04-25 18:07:40 +00:00
|
|
|
// If the target doesn't support this, we have to spill the input vector
|
|
|
|
// to a temporary stack slot, update the element, then reload it. This is
|
|
|
|
// badness. We could also load the value into a vector register (either
|
|
|
|
// with a "move to register" or "extload into register" instruction, then
|
|
|
|
// permute it into place, if the idx is a constant and if the idx is
|
|
|
|
// supported by the target.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Tmp1.getValueType();
|
|
|
|
MVT EltVT = VT.getVectorElementType();
|
|
|
|
MVT IdxVT = Tmp3.getValueType();
|
|
|
|
MVT PtrVT = TLI.getPointerTy();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StackPtr = DAG.CreateStackTemporary(VT);
|
2008-04-25 18:07:40 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
int SPFI = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex();
|
2008-04-25 18:07:40 +00:00
|
|
|
|
|
|
|
// Store the vector.
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Tmp1, StackPtr,
|
2008-10-30 08:01:45 +00:00
|
|
|
PseudoSourceValue::getFixedStack(SPFI), 0);
|
2008-04-25 18:07:40 +00:00
|
|
|
|
|
|
|
// Truncate or zero extend offset to target pointer type.
|
2008-06-08 20:54:56 +00:00
|
|
|
unsigned CastOpc = IdxVT.bitsGT(PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND;
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp3 = DAG.getNode(CastOpc, dl, PtrVT, Tmp3);
|
2008-04-25 18:07:40 +00:00
|
|
|
// Add the offset to the index.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned EltSize = EltVT.getSizeInBits()/8;
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::MUL, dl, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT));
|
|
|
|
SDValue StackPtr2 = DAG.getNode(ISD::ADD, dl, IdxVT, Tmp3, StackPtr);
|
2008-04-25 18:07:40 +00:00
|
|
|
// Store the scalar value.
|
2009-02-02 20:41:04 +00:00
|
|
|
Ch = DAG.getTruncStore(Ch, dl, Tmp2, StackPtr2,
|
2008-07-11 22:44:52 +00:00
|
|
|
PseudoSourceValue::getFixedStack(SPFI), 0, EltVT);
|
2008-04-25 18:07:40 +00:00
|
|
|
// Load the updated vector.
|
2009-02-02 20:41:04 +00:00
|
|
|
return DAG.getLoad(VT, dl, Ch, StackPtr,
|
2008-07-11 22:44:52 +00:00
|
|
|
PseudoSourceValue::getFixedStack(SPFI), 0);
|
2008-04-25 18:07:40 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 05:46:39 +00:00
|
|
|
|
2007-07-13 20:14:11 +00:00
|
|
|
/// LegalizeOp - We know that the specified value has a legal type, and
|
|
|
|
/// that its operands are legal. Now ensure that the operation itself
|
|
|
|
/// is legal, recursively ensuring that the operands' operations remain
|
|
|
|
/// legal.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) {
|
2007-08-25 01:00:22 +00:00
|
|
|
if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes.
|
|
|
|
return Op;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-08-24 16:35:28 +00:00
|
|
|
assert(isTypeLegal(Op.getValueType()) &&
|
2005-01-08 20:35:13 +00:00
|
|
|
"Caller should expand or promote operands that are not legal!");
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-01-30 23:10:59 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2005-01-08 20:35:13 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// If this operation defines any values that cannot be represented in a
|
2005-01-08 20:35:13 +00:00
|
|
|
// register on this target, make sure to expand or promote them.
|
2005-05-12 16:53:42 +00:00
|
|
|
if (Node->getNumValues() > 1) {
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
2006-03-18 01:44:44 +00:00
|
|
|
if (getTypeAction(Node->getValueType(i)) != Legal) {
|
|
|
|
HandleOp(Op.getValue(i));
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(LegalizedNodes.count(Op) &&
|
2006-03-18 01:44:44 +00:00
|
|
|
"Handling didn't add legal operands!");
|
2005-01-15 05:21:40 +00:00
|
|
|
return LegalizedNodes[Op];
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 16:53:42 +00:00
|
|
|
// Note that LegalizeOp may be reentered even from single-use nodes, which
|
|
|
|
// means that we always must cache transformed nodes.
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
|
2005-01-11 05:57:22 +00:00
|
|
|
if (I != LegalizedNodes.end()) return I->second;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp1, Tmp2, Tmp3, Tmp4;
|
|
|
|
SDValue Result = Op;
|
2006-01-28 07:39:30 +00:00
|
|
|
bool isCustom = false;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::FrameIndex:
|
|
|
|
case ISD::EntryToken:
|
|
|
|
case ISD::Register:
|
|
|
|
case ISD::BasicBlock:
|
|
|
|
case ISD::TargetFrameIndex:
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::TargetJumpTable:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::TargetConstant:
|
2006-01-29 06:26:56 +00:00
|
|
|
case ISD::TargetConstantFP:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::TargetConstantPool:
|
|
|
|
case ISD::TargetGlobalAddress:
|
2007-04-20 21:38:10 +00:00
|
|
|
case ISD::TargetGlobalTLSAddress:
|
2008-09-16 21:48:12 +00:00
|
|
|
case ISD::TargetExternalSymbol:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::VALUETYPE:
|
|
|
|
case ISD::SRCVALUE:
|
2008-02-06 22:27:42 +00:00
|
|
|
case ISD::MEMOPERAND:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::CONDCODE:
|
2008-03-21 09:14:45 +00:00
|
|
|
case ISD::ARG_FLAGS:
|
2006-01-28 08:31:04 +00:00
|
|
|
// Primitives must all be legal.
|
2007-10-16 09:07:20 +00:00
|
|
|
assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) &&
|
2006-01-28 08:31:04 +00:00
|
|
|
"This must be legal!");
|
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
default:
|
2005-05-14 06:34:48 +00:00
|
|
|
if (Node->getOpcode() >= ISD::BUILTIN_OP_END) {
|
|
|
|
// If this is a target node, legalize it by legalizing the operands then
|
|
|
|
// passing it through.
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2006-05-17 18:00:08 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
2005-05-14 06:34:48 +00:00
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-05-17 18:00:08 +00:00
|
|
|
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size());
|
2005-05-14 06:34:48 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
|
|
|
AddLegalizedOperand(Op.getValue(i), Result.getValue(i));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2005-05-14 06:34:48 +00:00
|
|
|
}
|
|
|
|
// Otherwise this is an unhandled builtin node. splat.
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(0 && "Do not know how to legalize this operator!");
|
|
|
|
abort();
|
2007-04-20 23:02:39 +00:00
|
|
|
case ISD::GLOBAL_OFFSET_TABLE:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::GlobalAddress:
|
2007-04-20 21:38:10 +00:00
|
|
|
case ISD::GlobalTLSAddress:
|
2008-09-16 21:48:12 +00:00
|
|
|
case ISD::ExternalSymbol:
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::ConstantPool:
|
|
|
|
case ISD::JumpTable: // Nothing to do.
|
2005-11-17 06:41:44 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 08:31:04 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 08:31:04 +00:00
|
|
|
// FALLTHROUGH if the target doesn't want to lower this op after all.
|
2005-11-17 06:41:44 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2007-01-29 22:58:52 +00:00
|
|
|
case ISD::FRAMEADDR:
|
|
|
|
case ISD::RETURNADDR:
|
|
|
|
// The only option for these nodes is to custom lower them. If the target
|
|
|
|
// does not custom lower them, then return zero.
|
|
|
|
Tmp1 = TLI.LowerOperation(Op, DAG);
|
2009-02-17 22:15:04 +00:00
|
|
|
if (Tmp1.getNode())
|
2007-01-29 22:58:52 +00:00
|
|
|
Result = Tmp1;
|
|
|
|
else
|
|
|
|
Result = DAG.getConstant(0, TLI.getPointerTy());
|
|
|
|
break;
|
2007-08-29 23:18:48 +00:00
|
|
|
case ISD::FRAME_TO_ARGS_OFFSET: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-08-29 19:28:29 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2007-08-29 19:28:29 +00:00
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Result = DAG.getConstant(0, VT);
|
|
|
|
break;
|
|
|
|
}
|
2007-08-29 23:18:48 +00:00
|
|
|
}
|
2007-08-29 19:28:29 +00:00
|
|
|
break;
|
2007-02-22 15:37:19 +00:00
|
|
|
case ISD::EXCEPTIONADDR: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-02-22 15:37:19 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand: {
|
2007-02-28 20:43:58 +00:00
|
|
|
unsigned Reg = TLI.getExceptionAddressRegister();
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getCopyFromReg(Tmp1, dl, Reg, VT);
|
2007-02-22 15:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2007-02-22 15:37:19 +00:00
|
|
|
// Fall Thru
|
2007-04-27 17:12:52 +00:00
|
|
|
case TargetLowering::Legal: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 };
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getMergeValues(Ops, 2, dl);
|
2007-02-28 20:43:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 17:12:52 +00:00
|
|
|
}
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()->getNumValues() == 1) break;
|
2007-12-31 18:35:50 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode()->getNumValues() == 2 &&
|
2007-12-31 18:35:50 +00:00
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
|
|
|
// Since we produced two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Tmp1);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp2 : Tmp1;
|
2007-02-28 20:43:58 +00:00
|
|
|
case ISD::EHSELECTION: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-02-28 20:43:58 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
unsigned Reg = TLI.getExceptionSelectorRegister();
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getCopyFromReg(Tmp2, dl, Reg, VT);
|
2007-02-28 20:43:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2007-02-28 20:43:58 +00:00
|
|
|
// Fall Thru
|
2007-04-27 17:12:52 +00:00
|
|
|
case TargetLowering::Legal: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 };
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getMergeValues(Ops, 2, dl);
|
2007-02-22 15:37:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 17:12:52 +00:00
|
|
|
}
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()->getNumValues() == 1) break;
|
2007-12-31 18:35:50 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode()->getNumValues() == 2 &&
|
2007-12-31 18:35:50 +00:00
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
|
|
|
// Since we produced two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Tmp1);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp2 : Tmp1;
|
2007-07-14 15:11:14 +00:00
|
|
|
case ISD::EH_RETURN: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-07-14 14:06:15 +00:00
|
|
|
// The only "good" option for this node is to custom lower it.
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported at all!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2007-07-14 14:06:15 +00:00
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// Target does not know, how to lower this, lower to noop
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
2007-07-14 15:11:14 +00:00
|
|
|
}
|
2007-07-14 14:06:15 +00:00
|
|
|
break;
|
2005-09-02 01:15:01 +00:00
|
|
|
case ISD::AssertSext:
|
|
|
|
case ISD::AssertZext:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-09-02 01:15:01 +00:00
|
|
|
break;
|
2005-11-20 22:56:56 +00:00
|
|
|
case ISD::MERGE_VALUES:
|
2006-01-28 10:58:55 +00:00
|
|
|
// Legalize eliminates MERGE_VALUES nodes.
|
2008-08-26 22:36:50 +00:00
|
|
|
Result = Node->getOperand(Op.getResNo());
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2005-01-14 22:38:01 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2005-12-18 15:27:43 +00:00
|
|
|
Result = Op.getValue(0);
|
2005-12-18 15:36:21 +00:00
|
|
|
if (Node->getNumValues() == 2) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-12-18 15:27:43 +00:00
|
|
|
} else {
|
2005-12-18 15:36:21 +00:00
|
|
|
assert(Node->getNumValues() == 3 && "Invalid copyfromreg!");
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Node->getNumOperands() == 3) {
|
2005-12-18 15:36:21 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(2));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2);
|
|
|
|
} else {
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
|
|
|
}
|
2005-12-18 15:27:43 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(2), Result.getValue(2));
|
|
|
|
}
|
2005-01-28 06:27:38 +00:00
|
|
|
// Since CopyFromReg produces two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Result);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2005-04-01 22:34:39 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::UNDEF, VT)) {
|
2005-04-02 00:41:14 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand:
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isInteger())
|
2005-04-01 22:34:39 +00:00
|
|
|
Result = DAG.getConstant(0, VT);
|
2008-06-06 12:08:01 +00:00
|
|
|
else if (VT.isFloatingPoint())
|
|
|
|
Result = DAG.getConstantFP(APFloat(APInt(VT.getSizeInBits(), 0)),
|
2007-09-26 17:26:49 +00:00
|
|
|
VT);
|
2005-04-01 22:34:39 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Unknown value type!");
|
|
|
|
break;
|
2005-04-02 00:41:14 +00:00
|
|
|
case TargetLowering::Legal:
|
2005-04-01 22:34:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-28 00:40:33 +00:00
|
|
|
case ISD::INTRINSIC_W_CHAIN:
|
|
|
|
case ISD::INTRINSIC_WO_CHAIN:
|
|
|
|
case ISD::INTRINSIC_VOID: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2006-03-24 02:26:29 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-26 09:12:51 +00:00
|
|
|
// Allow the target to custom lower its intrinsics if it wants to.
|
2009-02-17 22:15:04 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) ==
|
2006-03-26 09:12:51 +00:00
|
|
|
TargetLowering::Custom) {
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) Result = Tmp3;
|
2006-03-27 20:28:29 +00:00
|
|
|
}
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()->getNumValues() == 1) break;
|
2006-03-27 20:28:29 +00:00
|
|
|
|
|
|
|
// Must have return value and chain result.
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode()->getNumValues() == 2 &&
|
2006-03-27 20:28:29 +00:00
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
// Since loads produce two values, make sure to remember that we
|
2006-03-27 20:28:29 +00:00
|
|
|
// legalized both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2009-02-17 22:15:04 +00:00
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
|
2008-06-30 20:59:49 +00:00
|
|
|
case ISD::DBG_STOPPOINT:
|
|
|
|
assert(Node->getNumOperands() == 1 && "Invalid DBG_STOPPOINT node!");
|
2005-11-29 06:21:05 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain.
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-30 20:59:49 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::DBG_STOPPOINT, MVT::Other)) {
|
2005-11-29 06:21:05 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2009-02-13 02:16:35 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
DwarfWriter *DW = DAG.getDwarfWriter();
|
|
|
|
bool useDEBUG_LOC = TLI.isOperationLegalOrCustom(ISD::DEBUG_LOC,
|
|
|
|
MVT::Other);
|
|
|
|
bool useLABEL = TLI.isOperationLegalOrCustom(ISD::DBG_LABEL, MVT::Other);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-13 02:16:35 +00:00
|
|
|
const DbgStopPointSDNode *DSP = cast<DbgStopPointSDNode>(Node);
|
|
|
|
GlobalVariable *CU_GV = cast<GlobalVariable>(DSP->getCompileUnit());
|
|
|
|
if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) {
|
|
|
|
DICompileUnit CU(cast<GlobalVariable>(DSP->getCompileUnit()));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-13 02:16:35 +00:00
|
|
|
unsigned Line = DSP->getLine();
|
|
|
|
unsigned Col = DSP->getColumn();
|
2009-02-17 01:04:54 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel == CodeGenOpt::None) {
|
2009-02-17 01:04:54 +00:00
|
|
|
// A bit self-referential to have DebugLoc on Debug_Loc nodes, but it
|
|
|
|
// won't hurt anything.
|
|
|
|
if (useDEBUG_LOC) {
|
|
|
|
SDValue Ops[] = { Tmp1, DAG.getConstant(Line, MVT::i32),
|
2009-02-13 02:16:35 +00:00
|
|
|
DAG.getConstant(Col, MVT::i32),
|
2009-04-30 23:22:31 +00:00
|
|
|
DAG.getSrcValue(CU.getGV()) };
|
2009-02-17 01:04:54 +00:00
|
|
|
Result = DAG.getNode(ISD::DEBUG_LOC, dl, MVT::Other, Ops, 4);
|
|
|
|
} else {
|
2009-04-30 23:22:31 +00:00
|
|
|
unsigned ID = DW->RecordSourceLine(Line, Col, CU);
|
2009-02-17 01:04:54 +00:00
|
|
|
Result = DAG.getLabel(ISD::DBG_LABEL, dl, Tmp1, ID);
|
|
|
|
}
|
2009-02-13 02:16:35 +00:00
|
|
|
} else {
|
2009-02-17 01:04:54 +00:00
|
|
|
Result = Tmp1; // chain
|
2009-02-13 02:16:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Result = Tmp1; // chain
|
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
break;
|
2009-02-13 02:16:35 +00:00
|
|
|
}
|
2009-04-02 18:03:10 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2009-04-10 18:48:47 +00:00
|
|
|
if (Result.getNode())
|
2009-04-02 18:03:10 +00:00
|
|
|
break;
|
2008-07-08 20:06:39 +00:00
|
|
|
case TargetLowering::Legal: {
|
|
|
|
LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType());
|
|
|
|
if (Action == Legal && Tmp1 == Node->getOperand(0))
|
|
|
|
break;
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2008-07-08 20:06:39 +00:00
|
|
|
Ops.push_back(Tmp1);
|
|
|
|
if (Action == Legal) {
|
|
|
|
Ops.push_back(Node->getOperand(1)); // line # must be legal.
|
|
|
|
Ops.push_back(Node->getOperand(2)); // col # must be legal.
|
|
|
|
} else {
|
|
|
|
// Otherwise promote them.
|
|
|
|
Ops.push_back(PromoteOp(Node->getOperand(1)));
|
|
|
|
Ops.push_back(PromoteOp(Node->getOperand(2)));
|
2005-11-29 06:21:05 +00:00
|
|
|
}
|
2008-07-08 20:06:39 +00:00
|
|
|
Ops.push_back(Node->getOperand(3)); // filename must be legal.
|
|
|
|
Ops.push_back(Node->getOperand(4)); // working dir # must be legal.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-11-29 06:21:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-08 20:06:39 +00:00
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
break;
|
2008-02-02 04:07:54 +00:00
|
|
|
|
|
|
|
case ISD::DECLARE:
|
|
|
|
assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!");
|
|
|
|
switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
|
|
|
break;
|
2008-02-28 05:53:40 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
2008-02-02 04:07:54 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
break;
|
|
|
|
|
2005-12-16 22:45:29 +00:00
|
|
|
case ISD::DEBUG_LOC:
|
2006-01-05 01:25:28 +00:00
|
|
|
assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!");
|
2005-12-16 22:45:29 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2008-07-08 20:06:39 +00:00
|
|
|
case TargetLowering::Legal: {
|
|
|
|
LegalizeAction Action = getTypeAction(Node->getOperand(1).getValueType());
|
2006-01-05 01:25:28 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2008-07-08 20:06:39 +00:00
|
|
|
if (Action == Legal && Tmp1 == Node->getOperand(0))
|
|
|
|
break;
|
|
|
|
if (Action == Legal) {
|
|
|
|
Tmp2 = Node->getOperand(1);
|
|
|
|
Tmp3 = Node->getOperand(2);
|
|
|
|
Tmp4 = Node->getOperand(3);
|
|
|
|
} else {
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #.
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id.
|
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4);
|
2006-01-05 01:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-08 20:06:39 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
break;
|
2006-01-05 01:25:28 +00:00
|
|
|
|
2008-07-01 00:05:16 +00:00
|
|
|
case ISD::DBG_LABEL:
|
|
|
|
case ISD::EH_LABEL:
|
|
|
|
assert(Node->getNumOperands() == 1 && "Invalid LABEL node!");
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) {
|
2006-01-05 01:25:28 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2008-07-01 00:05:16 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-12-16 22:45:29 +00:00
|
|
|
break;
|
2007-03-03 19:21:38 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
2005-12-16 22:45:29 +00:00
|
|
|
}
|
2006-02-17 05:43:56 +00:00
|
|
|
break;
|
2005-11-29 06:21:05 +00:00
|
|
|
|
2008-03-08 00:58:38 +00:00
|
|
|
case ISD::PREFETCH:
|
|
|
|
assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!");
|
|
|
|
switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier.
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// It's a noop.
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:24:58 +00:00
|
|
|
case ISD::MEMBARRIER: {
|
|
|
|
assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!");
|
2008-02-16 14:46:26 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[6];
|
2008-02-16 14:46:26 +00:00
|
|
|
Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2008-02-27 08:53:44 +00:00
|
|
|
for (int x = 1; x < 6; ++x) {
|
|
|
|
Ops[x] = Node->getOperand(x);
|
|
|
|
if (!isTypeLegal(Ops[x].getValueType()))
|
|
|
|
Ops[x] = PromoteOp(Ops[x]);
|
|
|
|
}
|
2008-02-16 14:46:26 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
//There is no libgcc call for this op
|
|
|
|
Result = Node->getOperand(0); // Noop
|
|
|
|
break;
|
|
|
|
}
|
2008-02-16 01:24:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_CMP_SWAP: {
|
2008-05-05 19:05:59 +00:00
|
|
|
unsigned int num_operands = 4;
|
|
|
|
assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!");
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[4];
|
2008-05-05 19:05:59 +00:00
|
|
|
for (unsigned int x = 0; x < num_operands; ++x)
|
|
|
|
Ops[x] = LegalizeOp(Node->getOperand(x));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-05-05 19:05:59 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2008-07-04 11:47:58 +00:00
|
|
|
}
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_LOAD_ADD:
|
|
|
|
case ISD::ATOMIC_LOAD_SUB:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_NAND:
|
|
|
|
case ISD::ATOMIC_LOAD_MIN:
|
|
|
|
case ISD::ATOMIC_LOAD_MAX:
|
|
|
|
case ISD::ATOMIC_LOAD_UMIN:
|
|
|
|
case ISD::ATOMIC_LOAD_UMAX:
|
|
|
|
case ISD::ATOMIC_SWAP: {
|
2008-05-05 19:05:59 +00:00
|
|
|
unsigned int num_operands = 3;
|
|
|
|
assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!");
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[3];
|
2008-05-05 19:05:59 +00:00
|
|
|
for (unsigned int x = 0; x < num_operands; ++x)
|
2008-03-01 21:52:34 +00:00
|
|
|
Ops[x] = LegalizeOp(Node->getOperand(x));
|
2008-05-05 19:05:59 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands);
|
2008-07-04 11:47:58 +00:00
|
|
|
|
2008-03-01 21:52:34 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2008-02-21 06:45:13 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2008-03-01 21:52:34 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
2008-02-21 06:45:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2008-07-04 11:47:58 +00:00
|
|
|
}
|
2007-08-08 23:23:31 +00:00
|
|
|
case ISD::Constant: {
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Node);
|
|
|
|
unsigned opAction =
|
|
|
|
TLI.getOperationAction(ISD::Constant, CN->getValueType(0));
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// We know we don't need to expand constants here, constants only have one
|
|
|
|
// value and we check that it is fine above.
|
|
|
|
|
2007-08-08 23:23:31 +00:00
|
|
|
if (opAction == TargetLowering::Custom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode())
|
2007-08-08 23:23:31 +00:00
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2007-08-08 23:23:31 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ConstantFP: {
|
|
|
|
// Spill FP immediates to the constant pool if the target cannot directly
|
|
|
|
// codegen them. Targets often have some immediate values that can be
|
|
|
|
// efficiently generated into an FP register without a load. We explicitly
|
|
|
|
// leave these constants as ConstantFP nodes for the target to deal with.
|
|
|
|
ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node);
|
|
|
|
|
2006-01-29 06:26:56 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2008-02-14 08:57:00 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
2006-01-29 06:26:56 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-01-29 06:26:56 +00:00
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2008-02-14 08:57:00 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
// Check to see if this FP immediate is already legal.
|
|
|
|
bool isLegal = false;
|
|
|
|
for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(),
|
|
|
|
E = TLI.legal_fpimm_end(); I != E; ++I) {
|
|
|
|
if (CFP->isExactlyValue(*I)) {
|
|
|
|
isLegal = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If this is a legal constant, turn it into a TargetConstantFP node.
|
|
|
|
if (isLegal)
|
|
|
|
break;
|
2006-12-12 22:19:28 +00:00
|
|
|
Result = ExpandConstantFP(CFP, true, DAG, TLI);
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2008-02-14 08:57:00 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-09 18:48:57 +00:00
|
|
|
case ISD::TokenFactor:
|
|
|
|
if (Node->getNumOperands() == 2) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
} else if (Node->getNumOperands() == 3) {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2005-11-09 18:48:57 +00:00
|
|
|
} else {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2005-11-09 18:48:57 +00:00
|
|
|
// Legalize the operands.
|
2006-01-28 10:58:55 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-01-13 17:59:25 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-12 16:20:43 +00:00
|
|
|
case ISD::FORMAL_ARGUMENTS:
|
2006-05-16 22:53:20 +00:00
|
|
|
case ISD::CALL:
|
2006-04-12 16:20:43 +00:00
|
|
|
// The only option for this is to custom lower it.
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Tmp3.getNode() && "Target didn't custom lower this node!");
|
2008-03-05 19:14:03 +00:00
|
|
|
// A call within a calling sequence must be legalized to something
|
|
|
|
// other than the normal CALLSEQ_END. Violating this gets Legalize
|
|
|
|
// into an infinite loop.
|
|
|
|
assert ((!IsLegalizingCall ||
|
|
|
|
Node->getOpcode() != ISD::CALL ||
|
2008-08-28 21:40:38 +00:00
|
|
|
Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) &&
|
2008-03-05 19:14:03 +00:00
|
|
|
"Nested CALLSEQ_START..CALLSEQ_END not supported.");
|
2007-11-13 00:44:25 +00:00
|
|
|
|
|
|
|
// The number of incoming and outgoing values should match; unless the final
|
|
|
|
// outgoing value is a flag.
|
2008-08-28 21:40:38 +00:00
|
|
|
assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() ||
|
|
|
|
(Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 &&
|
|
|
|
Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) ==
|
2007-11-13 00:44:25 +00:00
|
|
|
MVT::Flag)) &&
|
2006-05-17 17:55:45 +00:00
|
|
|
"Lowering call/formal_arguments produced unexpected # results!");
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-05-16 22:53:20 +00:00
|
|
|
// Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to
|
2006-05-16 05:49:56 +00:00
|
|
|
// remember that we legalized all of them, so it doesn't get relegalized.
|
2008-08-28 21:40:38 +00:00
|
|
|
for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) {
|
|
|
|
if (Tmp3.getNode()->getValueType(i) == MVT::Flag)
|
2007-11-13 00:44:25 +00:00
|
|
|
continue;
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3.getValue(i));
|
2008-08-26 22:36:50 +00:00
|
|
|
if (Op.getResNo() == i)
|
2006-05-16 05:49:56 +00:00
|
|
|
Tmp2 = Tmp1;
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, i), Tmp1);
|
2006-05-16 05:49:56 +00:00
|
|
|
}
|
|
|
|
return Tmp2;
|
2006-03-19 00:52:58 +00:00
|
|
|
case ISD::BUILD_VECTOR:
|
|
|
|
switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) {
|
2006-03-19 01:17:20 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-03-19 01:17:20 +00:00
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2006-03-19 06:31:19 +00:00
|
|
|
case TargetLowering::Expand:
|
2008-08-28 21:40:38 +00:00
|
|
|
Result = ExpandBUILD_VECTOR(Result.getNode());
|
2006-03-19 00:52:58 +00:00
|
|
|
break;
|
2006-03-19 01:17:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::INSERT_VECTOR_ELT:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo
|
2008-02-13 06:43:04 +00:00
|
|
|
|
|
|
|
// The type of the value to insert may not be legal, even though the vector
|
|
|
|
// type is legal. Legalize/Promote accordingly. We do not handle Expand
|
|
|
|
// here.
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
default: assert(0 && "Cannot expand insert element operand");
|
|
|
|
case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break;
|
|
|
|
case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break;
|
2008-10-30 08:01:45 +00:00
|
|
|
case Expand:
|
|
|
|
// FIXME: An alternative would be to check to see if the target is not
|
2009-02-17 22:15:04 +00:00
|
|
|
// going to custom lower this operation, we could bitcast to half elt
|
2008-10-30 08:01:45 +00:00
|
|
|
// width and perform two inserts at that width, if that is legal.
|
|
|
|
Tmp2 = Node->getOperand(1);
|
|
|
|
break;
|
2008-02-13 06:43:04 +00:00
|
|
|
}
|
2006-03-19 01:17:20 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-19 01:17:20 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
2008-01-05 20:47:37 +00:00
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp4.getNode()) {
|
2008-01-05 20:47:37 +00:00
|
|
|
Result = Tmp4;
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2008-10-30 08:01:45 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
// Fall thru for vector case
|
2006-03-19 01:17:20 +00:00
|
|
|
case TargetLowering::Expand: {
|
Codegen insertelement with constant insertion points as scalar_to_vector
and a shuffle. For this:
void %test2(<4 x float>* %F, float %f) {
%tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
%tmp3 = add <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
%tmp2 = insertelement <4 x float> %tmp3, float %f, uint 2 ; <<4 x float>> [#uses=2]
%tmp6 = add <4 x float> %tmp2, %tmp2 ; <<4 x float>> [#uses=1]
store <4 x float> %tmp6, <4 x float>* %F
ret void
}
we now get this on X86 (which will get better):
_test2:
movl 4(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, %xmm1
shufps $3, %xmm1, %xmm1
movaps %xmm0, %xmm2
shufps $1, %xmm2, %xmm2
unpcklps %xmm1, %xmm2
movss 8(%esp), %xmm1
unpcklps %xmm1, %xmm0
unpcklps %xmm2, %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
ret
instead of:
_test2:
subl $28, %esp
movl 32(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%esp)
movss 36(%esp), %xmm0
movss %xmm0, 8(%esp)
movaps (%esp), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
addl $28, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27765 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-17 19:21:01 +00:00
|
|
|
// If the insert index is a constant, codegen this as a scalar_to_vector,
|
|
|
|
// then a shuffle that inserts it into the right position in the vector.
|
|
|
|
if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) {
|
2008-02-13 06:43:04 +00:00
|
|
|
// SCALAR_TO_VECTOR requires that the type of the value being inserted
|
2009-04-18 20:16:54 +00:00
|
|
|
// match the element type of the vector being created, except for
|
|
|
|
// integers in which case the inserted value can be over width.
|
|
|
|
MVT EltVT = Op.getValueType().getVectorElementType();
|
|
|
|
if (Tmp2.getValueType() == EltVT ||
|
|
|
|
(EltVT.isInteger() && Tmp2.getValueType().bitsGE(EltVT))) {
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
Tmp1.getValueType(), Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumElts = Tmp1.getValueType().getVectorNumElements();
|
2008-02-13 06:43:04 +00:00
|
|
|
// We generate a shuffle of InVec and ScVec, so the shuffle mask
|
|
|
|
// should be 0,1,2,3,4,5... with the appropriate element replaced with
|
|
|
|
// elt 0 of the RHS.
|
2009-04-27 18:41:29 +00:00
|
|
|
SmallVector<int, 8> ShufOps;
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i)
|
|
|
|
ShufOps.push_back(i != InsertPos->getZExtValue() ? i : NumElts);
|
|
|
|
|
|
|
|
Result = DAG.getVectorShuffle(Tmp1.getValueType(), dl, Tmp1, ScVec,
|
|
|
|
&ShufOps[0]);
|
2008-02-13 06:43:04 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
Codegen insertelement with constant insertion points as scalar_to_vector
and a shuffle. For this:
void %test2(<4 x float>* %F, float %f) {
%tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
%tmp3 = add <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
%tmp2 = insertelement <4 x float> %tmp3, float %f, uint 2 ; <<4 x float>> [#uses=2]
%tmp6 = add <4 x float> %tmp2, %tmp2 ; <<4 x float>> [#uses=1]
store <4 x float> %tmp6, <4 x float>* %F
ret void
}
we now get this on X86 (which will get better):
_test2:
movl 4(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, %xmm1
shufps $3, %xmm1, %xmm1
movaps %xmm0, %xmm2
shufps $1, %xmm2, %xmm2
unpcklps %xmm1, %xmm2
movss 8(%esp), %xmm1
unpcklps %xmm1, %xmm0
unpcklps %xmm2, %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
ret
instead of:
_test2:
subl $28, %esp
movl 32(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%esp)
movss 36(%esp), %xmm0
movss %xmm0, 8(%esp)
movaps (%esp), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
addl $28, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27765 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-17 19:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-02 20:41:04 +00:00
|
|
|
Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3, dl);
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-03-19 06:31:19 +00:00
|
|
|
case ISD::SCALAR_TO_VECTOR:
|
2006-04-04 17:23:26 +00:00
|
|
|
if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) {
|
|
|
|
Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node));
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
2006-03-19 06:47:21 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-03-19 06:47:21 +00:00
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2006-04-04 17:23:26 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node));
|
2006-03-19 06:31:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-04-27 18:41:29 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
2006-03-20 01:52:29 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors,
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask.
|
2009-04-27 18:41:29 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
MVT VT = Result.getValueType();
|
|
|
|
|
2009-04-29 05:20:52 +00:00
|
|
|
// Copy the Mask to a local SmallVector for use with isShuffleMaskLegal.
|
2009-04-27 18:41:29 +00:00
|
|
|
SmallVector<int, 8> Mask;
|
|
|
|
cast<ShuffleVectorSDNode>(Result)->getMask(Mask);
|
2006-03-20 01:52:29 +00:00
|
|
|
|
|
|
|
// Allow targets to custom lower the SHUFFLEs they support.
|
2009-04-27 18:41:29 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) {
|
2006-04-04 17:23:26 +00:00
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Legal:
|
2009-04-27 18:41:29 +00:00
|
|
|
assert(TLI.isShuffleMaskLegal(Mask, VT) &&
|
2006-04-04 17:23:26 +00:00
|
|
|
"vector shuffle should not be created if not legal!");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
2006-04-05 06:07:11 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-04-05 06:07:11 +00:00
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Expand: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT EltVT = VT.getVectorElementType();
|
2009-04-29 05:20:52 +00:00
|
|
|
unsigned NumElems = VT.getVectorNumElements();
|
2009-04-10 18:48:47 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2009-04-29 05:20:52 +00:00
|
|
|
for (unsigned i = 0; i != NumElems; ++i) {
|
2009-04-27 18:41:29 +00:00
|
|
|
if (Mask[i] < 0) {
|
2009-02-06 23:05:02 +00:00
|
|
|
Ops.push_back(DAG.getUNDEF(EltVT));
|
2009-04-27 18:41:29 +00:00
|
|
|
continue;
|
2006-04-05 06:07:11 +00:00
|
|
|
}
|
2009-04-29 05:20:52 +00:00
|
|
|
unsigned Idx = Mask[i];
|
2009-04-27 18:41:29 +00:00
|
|
|
if (Idx < NumElems)
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Tmp1,
|
|
|
|
DAG.getIntPtrConstant(Idx)));
|
|
|
|
else
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Tmp2,
|
|
|
|
DAG.getIntPtrConstant(Idx - NumElems)));
|
2006-04-05 06:07:11 +00:00
|
|
|
}
|
2009-02-25 22:49:59 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_VECTOR, dl, VT, &Ops[0], Ops.size());
|
2006-04-04 17:23:26 +00:00
|
|
|
break;
|
2006-04-05 06:07:11 +00:00
|
|
|
}
|
2006-04-04 17:23:26 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// Change base type to a different vector type.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OVT = Node->getValueType(0);
|
|
|
|
MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
2006-04-04 17:23:26 +00:00
|
|
|
|
|
|
|
// Cast the two input vectors.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-04 17:23:26 +00:00
|
|
|
// Convert the shuffle mask to the right # elements.
|
2009-04-29 05:20:52 +00:00
|
|
|
Result = ShuffleWithNarrowerEltType(NVT, OVT, dl, Tmp1, Tmp2, Mask);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, OVT, Result);
|
2006-04-04 17:23:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-03-20 01:52:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-27 18:41:29 +00:00
|
|
|
}
|
2006-03-21 20:44:12 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
2006-03-21 20:44:12 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-06-25 16:23:39 +00:00
|
|
|
Result = ExpandEXTRACT_VECTOR_ELT(Result);
|
2006-03-21 20:44:12 +00:00
|
|
|
break;
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
Result = ExpandEXTRACT_SUBVECTOR(Result);
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::CONCAT_VECTORS: {
|
2009-05-01 17:55:32 +00:00
|
|
|
// Legalize the operands.
|
2008-10-30 08:01:45 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2009-05-01 17:55:32 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::CONCAT_VECTORS,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.getNode()) {
|
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
// Use extract/insert/build vector for now. We might try to be
|
|
|
|
// more clever later.
|
|
|
|
MVT PtrVT = TLI.getPointerTy();
|
|
|
|
SmallVector<SDValue, 8> Ops;
|
|
|
|
unsigned NumOperands = Node->getNumOperands();
|
|
|
|
for (unsigned i=0; i < NumOperands; ++i) {
|
|
|
|
SDValue SubOp = Node->getOperand(i);
|
|
|
|
MVT VVT = SubOp.getNode()->getValueType(0);
|
|
|
|
MVT EltVT = VVT.getVectorElementType();
|
|
|
|
unsigned NumSubElem = VVT.getVectorNumElements();
|
|
|
|
for (unsigned j=0; j < NumSubElem; ++j) {
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, SubOp,
|
|
|
|
DAG.getConstant(j, PtrVT)));
|
|
|
|
}
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
2009-05-01 17:55:32 +00:00
|
|
|
return LegalizeOp(DAG.getNode(ISD::BUILD_VECTOR, dl,
|
|
|
|
Node->getValueType(0),
|
|
|
|
&Ops[0], Ops.size()));
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
2009-05-01 17:55:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
case ISD::CALLSEQ_START: {
|
|
|
|
SDNode *CallEnd = FindCallEndFromCallStart(Node);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Recursively Legalize all of the inputs of the call end that do not lead
|
|
|
|
// to this call start. This ensures that any libcalls that need be inserted
|
|
|
|
// are inserted *before* the CALLSEQ_START.
|
2009-02-04 19:38:14 +00:00
|
|
|
IsLegalizingCallArgs = true;
|
2007-02-04 00:27:56 +00:00
|
|
|
{SmallPtrSet<SDNode*, 32> NodesLeadingTo;
|
2006-02-13 09:18:02 +00:00
|
|
|
for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i)
|
2008-08-28 21:40:38 +00:00
|
|
|
LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node,
|
2006-07-26 23:55:56 +00:00
|
|
|
NodesLeadingTo);
|
|
|
|
}
|
2009-02-04 19:38:14 +00:00
|
|
|
IsLegalizingCallArgs = false;
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Now that we legalized all of the inputs (which may have inserted
|
|
|
|
// libcalls) create the new CALLSEQ_START node.
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
|
|
|
|
// Merge in the last call, to ensure that this call start after the last
|
|
|
|
// call ended.
|
2006-05-17 18:00:08 +00:00
|
|
|
if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1, LastCALLSEQ_END);
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Do not try to legalize the target-specific arguments (#1+).
|
|
|
|
if (Tmp1 != Node->getOperand(0)) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-02-13 09:18:02 +00:00
|
|
|
Ops[0] = Tmp1;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-02-13 09:18:02 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Remember that the CALLSEQ_START is legalized.
|
2006-02-14 00:55:02 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(0), Result);
|
|
|
|
if (Node->getNumValues() == 2) // If this has a flag result, remember it.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Result.getValue(1));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Now that the callseq_start and all of the non-call nodes above this call
|
2009-02-17 22:15:04 +00:00
|
|
|
// sequence have been legalized, legalize the call itself. During this
|
2006-02-13 09:18:02 +00:00
|
|
|
// process, no libcalls can/will be inserted, guaranteeing that no calls
|
|
|
|
// can overlap.
|
|
|
|
assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!");
|
|
|
|
// Note that we are selecting this call!
|
2008-07-27 21:46:04 +00:00
|
|
|
LastCALLSEQ_END = SDValue(CallEnd, 0);
|
2006-02-13 09:18:02 +00:00
|
|
|
IsLegalizingCall = true;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Legalize the call, starting from the CALLSEQ_END.
|
|
|
|
LegalizeOp(LastCALLSEQ_END);
|
|
|
|
assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!");
|
|
|
|
return Result;
|
|
|
|
}
|
2005-05-12 23:24:06 +00:00
|
|
|
case ISD::CALLSEQ_END:
|
2006-02-13 09:18:02 +00:00
|
|
|
// If the CALLSEQ_START node hasn't been legalized first, legalize it. This
|
|
|
|
// will cause this node to be legalized as well as handling libcalls right.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (LastCALLSEQ_END.getNode() != Node) {
|
2008-07-27 21:46:04 +00:00
|
|
|
LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0));
|
|
|
|
DenseMap<SDValue, SDValue>::iterator I = LegalizedNodes.find(Op);
|
2006-02-13 09:18:02 +00:00
|
|
|
assert(I != LegalizedNodes.end() &&
|
|
|
|
"Legalizing the call start should have legalized this node!");
|
|
|
|
return I->second;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// Otherwise, the call start has been legalized and everything is going
|
2006-02-13 09:18:02 +00:00
|
|
|
// according to plan. Just legalize ourselves normally here.
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-29 07:58:15 +00:00
|
|
|
// Do not try to legalize the target-specific arguments (#1+), except for
|
|
|
|
// an optional flag input.
|
|
|
|
if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){
|
|
|
|
if (Tmp1 != Node->getOperand(0)) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-01-29 07:58:15 +00:00
|
|
|
Ops[0] = Tmp1;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-01-29 07:58:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1));
|
|
|
|
if (Tmp1 != Node->getOperand(0) ||
|
|
|
|
Tmp2 != Node->getOperand(Node->getNumOperands()-1)) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-01-29 07:58:15 +00:00
|
|
|
Ops[0] = Tmp1;
|
|
|
|
Ops.back() = Tmp2;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-01-29 07:58:15 +00:00
|
|
|
}
|
2006-01-24 05:48:21 +00:00
|
|
|
}
|
2006-02-14 00:55:02 +00:00
|
|
|
assert(IsLegalizingCall && "Call sequence imbalance between start/end?");
|
2006-02-13 09:18:02 +00:00
|
|
|
// This finishes up call legalization.
|
|
|
|
IsLegalizingCall = false;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-14 00:55:02 +00:00
|
|
|
// If the CALLSEQ_END node has a flag, remember that we legalized it.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
2006-02-14 00:55:02 +00:00
|
|
|
if (Node->getNumValues() == 2)
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2006-01-11 22:14:47 +00:00
|
|
|
case ISD::DYNAMIC_STACKALLOC: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2005-01-09 19:03:49 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2005-01-09 19:03:49 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = Result.getValue(0);
|
2006-01-15 08:43:08 +00:00
|
|
|
Tmp2 = Result.getValue(1);
|
2007-08-16 23:50:06 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
2006-01-11 22:14:47 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-15 08:54:32 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore();
|
|
|
|
assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and"
|
|
|
|
" not tell us which reg is the stack pointer!");
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Chain = Tmp1.getOperand(0);
|
2007-11-13 00:44:25 +00:00
|
|
|
|
|
|
|
// Chain the dynamic stack allocation so that it doesn't modify the stack
|
|
|
|
// pointer when other instructions are using the stack.
|
2008-10-11 22:08:30 +00:00
|
|
|
Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(0, true));
|
2007-11-13 00:44:25 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Size = Tmp2.getOperand(1);
|
2009-02-04 00:13:36 +00:00
|
|
|
SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
|
2007-08-16 23:50:06 +00:00
|
|
|
Chain = SP.getValue(1);
|
2008-09-12 16:56:44 +00:00
|
|
|
unsigned Align = cast<ConstantSDNode>(Tmp3)->getZExtValue();
|
2007-08-16 23:50:06 +00:00
|
|
|
unsigned StackAlign =
|
|
|
|
TLI.getTargetMachine().getFrameInfo()->getStackAlignment();
|
|
|
|
if (Align > StackAlign)
|
2009-02-02 23:46:53 +00:00
|
|
|
SP = DAG.getNode(ISD::AND, dl, VT, SP,
|
2007-08-17 18:02:22 +00:00
|
|
|
DAG.getConstant(-(uint64_t)Align, VT));
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SUB, dl, VT, SP, Size); // Value
|
2009-02-04 00:13:36 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, SPReg, Tmp1); // Output chain
|
2007-11-13 00:44:25 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, true),
|
2008-10-11 22:08:30 +00:00
|
|
|
DAG.getIntPtrConstant(0, true), SDValue());
|
2007-11-13 00:44:25 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Custom:
|
2006-01-15 08:43:08 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Tmp1, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
2006-01-11 22:14:47 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-01-15 08:54:32 +00:00
|
|
|
// Since this op produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp2 : Tmp1;
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-07-11 01:40:09 +00:00
|
|
|
case ISD::INLINEASM: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-07-11 01:40:09 +00:00
|
|
|
bool Changed = false;
|
|
|
|
// Legalize all of the operands of the inline asm, in case they are nodes
|
|
|
|
// that need to be expanded or something. Note we skip the asm string and
|
|
|
|
// all of the TargetConstant flags.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op = LegalizeOp(Ops[0]);
|
2006-07-11 01:40:09 +00:00
|
|
|
Changed = Op != Ops[0];
|
|
|
|
Ops[0] = Op;
|
|
|
|
|
|
|
|
bool HasInFlag = Ops.back().getValueType() == MVT::Flag;
|
|
|
|
for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) {
|
2009-03-20 18:03:34 +00:00
|
|
|
unsigned NumVals = InlineAsm::
|
|
|
|
getNumOperandRegisters(cast<ConstantSDNode>(Ops[i])->getZExtValue());
|
2006-07-11 01:40:09 +00:00
|
|
|
for (++i; NumVals; ++i, --NumVals) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op = LegalizeOp(Ops[i]);
|
2006-07-11 01:40:09 +00:00
|
|
|
if (Op != Ops[i]) {
|
|
|
|
Changed = true;
|
|
|
|
Ops[i] = Op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasInFlag) {
|
|
|
|
Op = LegalizeOp(Ops.back());
|
|
|
|
Changed |= Op != Ops.back();
|
|
|
|
Ops.back() = Op;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-07-11 01:40:09 +00:00
|
|
|
if (Changed)
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-26 22:24:51 +00:00
|
|
|
// INLINE asm returns a chain and flag, make sure to add both to the map.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2006-07-11 01:40:09 +00:00
|
|
|
}
|
2005-01-07 22:12:08 +00:00
|
|
|
case ISD::BR:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a branch.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-02-13 09:18:02 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-01-07 22:12:08 +00:00
|
|
|
break;
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::BRIND:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
// Ensure that libcalls are emitted before a branch.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-04-22 18:53:45 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
default: assert(0 && "Indirect target must be legal type (pointer)!");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
break;
|
2006-10-30 08:00:44 +00:00
|
|
|
case ISD::BR_JT:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
// Ensure that libcalls are emitted before a branch.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-10-30 08:00:44 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) {
|
2006-10-30 08:00:44 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-10-30 08:00:44 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Chain = Result.getOperand(0);
|
|
|
|
SDValue Table = Result.getOperand(1);
|
|
|
|
SDValue Index = Result.getOperand(2);
|
2006-10-30 08:00:44 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PTy = TLI.getPointerTy();
|
2006-12-14 19:17:33 +00:00
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize();
|
2009-02-17 22:15:04 +00:00
|
|
|
Index= DAG.getNode(ISD::MUL, dl, PTy,
|
2009-02-02 23:46:53 +00:00
|
|
|
Index, DAG.getConstant(EntrySize, PTy));
|
|
|
|
SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table);
|
2006-12-14 19:17:33 +00:00
|
|
|
|
2008-12-12 08:13:38 +00:00
|
|
|
MVT MemVT = MVT::getIntegerVT(EntrySize * 8);
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue LD = DAG.getExtLoad(ISD::SEXTLOAD, dl, PTy, Chain, Addr,
|
2008-12-12 08:13:38 +00:00
|
|
|
PseudoSourceValue::getJumpTable(), 0, MemVT);
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
Addr = LD;
|
2006-12-14 19:17:33 +00:00
|
|
|
if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
2006-10-30 08:00:44 +00:00
|
|
|
// For PIC, the sequence is:
|
|
|
|
// BRIND(load(Jumptable + index) + RelocBase)
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
// RelocBase can be JumpTable, GOT or some sort of global base.
|
2009-02-02 23:46:53 +00:00
|
|
|
Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr,
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
TLI.getPICJumpTableRelocBase(Table, DAG));
|
2006-10-30 08:00:44 +00:00
|
|
|
}
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::BRIND, dl, MVT::Other, LD.getValue(1), Addr);
|
2006-10-30 08:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-01-07 08:19:42 +00:00
|
|
|
case ISD::BRCOND:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a return.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-02-13 09:18:02 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
2005-01-18 19:27:06 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
case Expand: assert(0 && "It's impossible to expand bools");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition.
|
|
|
|
break;
|
2008-02-25 21:11:39 +00:00
|
|
|
case Promote: {
|
2005-01-18 19:27:06 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition.
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-11-27 04:39:56 +00:00
|
|
|
// The top bits of the promoted condition are not necessarily zero, ensure
|
|
|
|
// that the value is properly zero extended.
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned BitWidth = Tmp2.getValueSizeInBits();
|
2009-02-17 22:15:04 +00:00
|
|
|
if (!DAG.MaskedValueIsZero(Tmp2,
|
2008-02-25 21:11:39 +00:00
|
|
|
APInt::getHighBitsSet(BitWidth, BitWidth-1)))
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, dl, MVT::i1);
|
2005-01-18 19:27:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Basic block destination (Op#2) is always legal.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) {
|
2005-08-16 19:49:35 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2005-08-16 19:49:35 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
// Expand brcond's setcc into its constituent parts and create a BR_CC
|
|
|
|
// Node.
|
|
|
|
if (Tmp2.getOpcode() == ISD::SETCC) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other,
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1, Tmp2.getOperand(2),
|
2005-08-16 19:49:35 +00:00
|
|
|
Tmp2.getOperand(0), Tmp2.getOperand(1),
|
|
|
|
Node->getOperand(2));
|
|
|
|
} else {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::BR_CC, dl, MVT::Other, Tmp1,
|
2005-08-16 19:49:35 +00:00
|
|
|
DAG.getCondCode(ISD::SETNE), Tmp2,
|
|
|
|
DAG.getConstant(0, Tmp2.getValueType()),
|
|
|
|
Node->getOperand(2));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::BR_CC:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a branch.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-02-13 09:18:02 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
2009-02-17 22:15:04 +00:00
|
|
|
Tmp2 = Node->getOperand(2); // LHS
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp3 = Node->getOperand(3); // RHS
|
|
|
|
Tmp4 = Node->getOperand(1); // CC
|
2005-12-17 23:46:46 +00:00
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
LegalizeSetCC(TLI.getSetCCResultType(Tmp2.getValueType()),
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2, Tmp3, Tmp4, dl);
|
2006-12-18 22:55:34 +00:00
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
2008-10-15 02:05:31 +00:00
|
|
|
// If we didn't get both a LHS and RHS back from LegalizeSetCC,
|
2006-02-01 07:19:44 +00:00
|
|
|
// the LHS is a legal SETCC itself. In this case, we need to compare
|
|
|
|
// the result against zero to select between true and false values.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode() == 0) {
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp3 = DAG.getConstant(0, Tmp2.getValueType());
|
|
|
|
Tmp4 = DAG.getCondCode(ISD::SETNE);
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3,
|
2006-02-01 07:19:44 +00:00
|
|
|
Node->getOperand(4));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-17 23:46:46 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) {
|
|
|
|
default: assert(0 && "Unexpected action for BR_CC!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp4.getNode()) Result = Tmp4;
|
2005-12-17 23:46:46 +00:00
|
|
|
break;
|
2005-08-16 19:49:35 +00:00
|
|
|
}
|
2005-01-07 08:19:42 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
case ISD::LOAD: {
|
2006-10-09 20:57:25 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
|
|
|
Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer.
|
2005-04-27 20:10:01 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
|
|
|
if (ExtType == ISD::NON_EXTLOAD) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2006-10-09 20:57:25 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset());
|
|
|
|
Tmp3 = Result.getValue(0);
|
|
|
|
Tmp4 = Result.getValue(1);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2007-08-01 19:34:21 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned load and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-06-06 12:08:01 +00:00
|
|
|
getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
|
2007-08-01 19:34:21 +00:00
|
|
|
if (LD->getAlignment() < ABIAlignment){
|
2008-08-28 21:40:38 +00:00
|
|
|
Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG,
|
2007-08-01 19:34:21 +00:00
|
|
|
TLI);
|
|
|
|
Tmp3 = Result.getOperand(0);
|
|
|
|
Tmp4 = Result.getOperand(1);
|
2007-09-08 19:29:23 +00:00
|
|
|
Tmp3 = LegalizeOp(Tmp3);
|
|
|
|
Tmp4 = LegalizeOp(Tmp4);
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-10-09 20:57:25 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp3, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) {
|
2006-10-09 20:57:25 +00:00
|
|
|
Tmp3 = LegalizeOp(Tmp1);
|
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// Only promote a load of vector type to another.
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(VT.isVector() && "Cannot promote this load!");
|
2006-10-09 20:57:25 +00:00
|
|
|
// Change base type to a different vector type.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
|
2006-10-09 20:57:25 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getLoad(NVT, dl, Tmp1, Tmp2, LD->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
LD->getSrcValueOffset(),
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
2009-02-07 00:55:49 +00:00
|
|
|
Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, dl, VT, Tmp1));
|
2006-04-12 16:33:18 +00:00
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
2006-10-09 20:57:25 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2006-10-09 20:57:25 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
// Since loads produce two values, make sure to remember that we
|
2006-10-09 20:57:25 +00:00
|
|
|
// legalized both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp3);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp4);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp4 : Tmp3;
|
2006-10-09 20:57:25 +00:00
|
|
|
} else {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT SrcVT = LD->getMemoryVT();
|
|
|
|
unsigned SrcWidth = SrcVT.getSizeInBits();
|
2008-01-23 20:39:46 +00:00
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
if (SrcWidth != SrcVT.getStoreSizeInBits() &&
|
2008-01-23 20:39:46 +00:00
|
|
|
// Some targets pretend to have an i1 loading operation, and actually
|
|
|
|
// load an i8. This trick is correct for ZEXTLOAD because the top 7
|
|
|
|
// bits are guaranteed to be zero; it helps the optimizers understand
|
|
|
|
// that these bits are zero. It is also useful for EXTLOAD, since it
|
|
|
|
// tells the optimizers that those bits are undefined. It would be
|
|
|
|
// nice to have an effective generic way of getting these benefits...
|
|
|
|
// Until such a way is found, don't insist on promoting i1 here.
|
|
|
|
(SrcVT != MVT::i1 ||
|
2008-10-14 21:26:46 +00:00
|
|
|
TLI.getLoadExtAction(ExtType, MVT::i1) == TargetLowering::Promote)) {
|
2008-01-23 20:39:46 +00:00
|
|
|
// Promote to a byte-sized load if not loading an integral number of
|
|
|
|
// bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NewWidth = SrcVT.getStoreSizeInBits();
|
|
|
|
MVT NVT = MVT::getIntegerVT(NewWidth);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ch;
|
2008-01-23 20:39:46 +00:00
|
|
|
|
|
|
|
// The extra bits are guaranteed to be zero, since we stored them that
|
|
|
|
// way. A zext load from NVT thus automatically gives zext from SrcVT.
|
|
|
|
|
|
|
|
ISD::LoadExtType NewExtType =
|
|
|
|
ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD;
|
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getExtLoad(NewExtType, dl, Node->getValueType(0),
|
2008-01-23 20:39:46 +00:00
|
|
|
Tmp1, Tmp2, LD->getSrcValue(), SVOffset,
|
|
|
|
NVT, isVolatile, Alignment);
|
|
|
|
|
|
|
|
Ch = Result.getValue(1); // The chain.
|
|
|
|
|
|
|
|
if (ExtType == ISD::SEXTLOAD)
|
|
|
|
// Having the top bits zero doesn't help when sign extending.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
Result.getValueType(),
|
2008-01-23 20:39:46 +00:00
|
|
|
Result, DAG.getValueType(SrcVT));
|
|
|
|
else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType())
|
|
|
|
// All the top bits are guaranteed to be zero - inform the optimizers.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::AssertZext, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
Result.getValueType(), Result,
|
2008-01-23 20:39:46 +00:00
|
|
|
DAG.getValueType(SrcVT));
|
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Ch);
|
|
|
|
} else if (SrcWidth & (SrcWidth - 1)) {
|
|
|
|
// If not loading a power-of-2 number of bits, expand as two loads.
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(SrcVT.isExtended() && !SrcVT.isVector() &&
|
2008-01-23 20:39:46 +00:00
|
|
|
"Unsupported extload!");
|
|
|
|
unsigned RoundWidth = 1 << Log2_32(SrcWidth);
|
|
|
|
assert(RoundWidth < SrcWidth);
|
|
|
|
unsigned ExtraWidth = SrcWidth - RoundWidth;
|
|
|
|
assert(ExtraWidth < RoundWidth);
|
|
|
|
assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
|
|
|
|
"Load size not an integral number of bytes!");
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT RoundVT = MVT::getIntegerVT(RoundWidth);
|
|
|
|
MVT ExtraVT = MVT::getIntegerVT(ExtraWidth);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi, Ch;
|
2008-01-23 20:39:46 +00:00
|
|
|
unsigned IncrementSize;
|
|
|
|
|
|
|
|
if (TLI.isLittleEndian()) {
|
|
|
|
// EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16)
|
|
|
|
// Load the bottom RoundWidth bits.
|
2009-02-02 23:46:53 +00:00
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl,
|
|
|
|
Node->getValueType(0), Tmp1, Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
LD->getSrcValue(), SVOffset, RoundVT, isVolatile,
|
|
|
|
Alignment);
|
|
|
|
|
|
|
|
// Load the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getExtLoad(ExtType, dl, Node->getValueType(0), Tmp1, Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
LD->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
2009-02-02 23:46:53 +00:00
|
|
|
Ch = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
|
2008-01-23 20:39:46 +00:00
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Move the top bits to the right place.
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getNode(ISD::SHL, dl, Hi.getValueType(), Hi,
|
2008-01-23 20:39:46 +00:00
|
|
|
DAG.getConstant(RoundWidth, TLI.getShiftAmountTy()));
|
|
|
|
|
|
|
|
// Join the hi and lo parts.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, dl, Node->getValueType(0), Lo, Hi);
|
2007-08-01 19:34:21 +00:00
|
|
|
} else {
|
2008-01-23 20:39:46 +00:00
|
|
|
// Big endian - avoid unaligned loads.
|
|
|
|
// EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8
|
|
|
|
// Load the top RoundWidth bits.
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getExtLoad(ExtType, dl, Node->getValueType(0), Tmp1, Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
LD->getSrcValue(), SVOffset, RoundVT, isVolatile,
|
|
|
|
Alignment);
|
|
|
|
|
|
|
|
// Load the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2009-02-17 22:15:04 +00:00
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
Node->getValueType(0), Tmp1, Tmp2,
|
2008-01-23 20:39:46 +00:00
|
|
|
LD->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
2009-02-02 23:46:53 +00:00
|
|
|
Ch = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
|
2008-01-23 20:39:46 +00:00
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Move the top bits to the right place.
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getNode(ISD::SHL, dl, Hi.getValueType(), Hi,
|
2008-01-23 20:39:46 +00:00
|
|
|
DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy()));
|
|
|
|
|
|
|
|
// Join the hi and lo parts.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, dl, Node->getValueType(0), Lo, Hi);
|
2008-01-23 20:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Ch);
|
|
|
|
} else {
|
2008-10-14 21:26:46 +00:00
|
|
|
switch (TLI.getLoadExtAction(ExtType, SrcVT)) {
|
2008-01-23 20:39:46 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset());
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
|
|
|
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2008-01-23 20:39:46 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If this is an unaligned load and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-06-06 12:08:01 +00:00
|
|
|
getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
|
2008-01-23 20:39:46 +00:00
|
|
|
if (LD->getAlignment() < ABIAlignment){
|
2008-08-28 21:40:38 +00:00
|
|
|
Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.getNode()), DAG,
|
2008-01-23 20:39:46 +00:00
|
|
|
TLI);
|
|
|
|
Tmp1 = Result.getOperand(0);
|
|
|
|
Tmp2 = Result.getOperand(1);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
|
|
|
}
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-23 20:39:46 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND
|
|
|
|
if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) {
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue Load = DAG.getLoad(SrcVT, dl, Tmp1, Tmp2, LD->getSrcValue(),
|
2008-01-23 20:39:46 +00:00
|
|
|
LD->getSrcValueOffset(),
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
Node->getValueType(0), Load);
|
2008-01-23 20:39:46 +00:00
|
|
|
Tmp1 = LegalizeOp(Result); // Relegalize new nodes.
|
|
|
|
Tmp2 = LegalizeOp(Load.getValue(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!");
|
|
|
|
// Turn the unsupported load into an EXTLOAD followed by an explicit
|
|
|
|
// zero/sign extend inreg.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getExtLoad(ISD::EXTLOAD, dl, Node->getValueType(0),
|
2008-01-23 20:39:46 +00:00
|
|
|
Tmp1, Tmp2, LD->getSrcValue(),
|
|
|
|
LD->getSrcValueOffset(), SrcVT,
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ValRes;
|
2008-01-23 20:39:46 +00:00
|
|
|
if (ExtType == ISD::SEXTLOAD)
|
2009-02-02 23:46:53 +00:00
|
|
|
ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl,
|
|
|
|
Result.getValueType(),
|
2008-01-23 20:39:46 +00:00
|
|
|
Result, DAG.getValueType(SrcVT));
|
|
|
|
else
|
2009-02-02 23:46:53 +00:00
|
|
|
ValRes = DAG.getZeroExtendInReg(Result, dl, SrcVT);
|
2008-01-23 20:39:46 +00:00
|
|
|
Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes.
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes.
|
2006-10-09 20:57:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-06-30 19:22:37 +00:00
|
|
|
}
|
2008-01-23 20:39:46 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
// Since loads produce two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp2 : Tmp1;
|
2005-04-10 22:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-19 00:06:56 +00:00
|
|
|
case ISD::EXTRACT_ELEMENT: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OpTy = Node->getOperand(0).getValueType();
|
2005-10-19 00:06:56 +00:00
|
|
|
switch (getTypeAction(OpTy)) {
|
2006-01-28 10:58:55 +00:00
|
|
|
default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!");
|
2005-10-19 00:06:56 +00:00
|
|
|
case Legal:
|
2008-09-12 16:56:44 +00:00
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue()) {
|
2005-10-19 00:06:56 +00:00
|
|
|
// 1 -> Hi
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SRL, dl, OpTy, Node->getOperand(0),
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(OpTy.getSizeInBits()/2,
|
2005-10-19 00:06:56 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), Result);
|
2005-10-19 00:06:56 +00:00
|
|
|
} else {
|
|
|
|
// 0 -> Lo
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0),
|
2005-10-19 00:06:56 +00:00
|
|
|
Node->getOperand(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
// Get both the low and high parts.
|
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
2008-09-12 16:56:44 +00:00
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue())
|
2005-10-19 00:06:56 +00:00
|
|
|
Result = Tmp2; // 1 -> Hi
|
|
|
|
else
|
|
|
|
Result = Tmp1; // 0 -> Lo
|
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-10-19 00:06:56 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
case ISD::CopyToReg:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-08-24 16:35:28 +00:00
|
|
|
assert(isTypeLegal(Node->getOperand(2).getValueType()) &&
|
2005-08-16 21:55:35 +00:00
|
|
|
"Register type must be legal!");
|
2005-12-18 15:27:43 +00:00
|
|
|
// Legalize the incoming value (must be a legal type).
|
2005-08-16 21:55:35 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(2));
|
2005-12-18 15:36:21 +00:00
|
|
|
if (Node->getNumValues() == 1) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2);
|
2005-12-18 15:27:43 +00:00
|
|
|
} else {
|
2005-12-18 15:36:21 +00:00
|
|
|
assert(Node->getNumValues() == 2 && "Unknown CopyToReg");
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Node->getNumOperands() == 4) {
|
2005-12-18 15:36:21 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(3));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2,
|
|
|
|
Tmp3);
|
|
|
|
} else {
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2);
|
2005-12-18 15:27:43 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-18 15:27:43 +00:00
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Result.getValue(1));
|
2006-01-28 10:58:55 +00:00
|
|
|
return Result;
|
2005-12-18 15:27:43 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::RET:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Ensure that libcalls are emitted before a return.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Tmp1, LastCALLSEQ_END);
|
2006-02-13 09:18:02 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (Node->getNumOperands()) {
|
2006-05-26 23:09:09 +00:00
|
|
|
case 3: // ret val
|
2006-04-11 06:33:39 +00:00
|
|
|
Tmp2 = Node->getOperand(1);
|
2006-05-26 23:09:09 +00:00
|
|
|
Tmp3 = Node->getOperand(2); // Signness
|
2006-04-11 01:31:51 +00:00
|
|
|
switch (getTypeAction(Tmp2.getValueType())) {
|
2005-01-07 07:47:09 +00:00
|
|
|
case Legal:
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2006-04-11 01:31:51 +00:00
|
|
|
case Expand:
|
2008-06-06 12:08:01 +00:00
|
|
|
if (!Tmp2.getValueType().isVector()) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2006-04-11 01:31:51 +00:00
|
|
|
ExpandOp(Tmp2, Lo, Hi);
|
2007-03-06 20:01:06 +00:00
|
|
|
|
|
|
|
// Big endian systems want the hi reg first.
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2007-03-06 20:01:06 +00:00
|
|
|
std::swap(Lo, Hi);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Hi.getNode())
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, dl, MVT::Other,
|
2009-04-10 18:48:47 +00:00
|
|
|
Tmp1, Lo, Tmp3, Hi, Tmp3);
|
2006-12-11 19:27:14 +00:00
|
|
|
else
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, dl, MVT::Other, Tmp1, Lo, Tmp3);
|
2006-08-21 20:24:53 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2006-04-11 01:31:51 +00:00
|
|
|
} else {
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *InVal = Tmp2.getNode();
|
2008-08-26 22:36:50 +00:00
|
|
|
int InIx = Tmp2.getResNo();
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements();
|
|
|
|
MVT EVT = InVal->getValueType(InIx).getVectorElementType();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
2007-02-15 03:39:18 +00:00
|
|
|
// type. If so, convert to the vector type.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT TVT = MVT::getVectorVT(EVT, NumElems);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-02-15 03:39:18 +00:00
|
|
|
// Turn this into a return of the vector type.
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-04-11 01:31:51 +00:00
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a return of the scalar type.
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp2 = ScalarizeVectorOp(Tmp2);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-11 02:00:08 +00:00
|
|
|
// FIXME: Returns of gcc generic vectors smaller than a legal type
|
|
|
|
// should be returned in integer registers!
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-11 01:31:51 +00:00
|
|
|
// The scalarized value type may not be legal, e.g. it might require
|
|
|
|
// promotion or expansion. Relegalize the return.
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
} else {
|
2006-04-11 02:00:08 +00:00
|
|
|
// FIXME: Returns of gcc generic vectors larger than a legal vector
|
|
|
|
// type should be returned by reference!
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2006-04-11 01:31:51 +00:00
|
|
|
SplitVectorOp(Tmp2, Lo, Hi);
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, dl, MVT::Other,
|
2009-04-10 18:48:47 +00:00
|
|
|
Tmp1, Lo, Tmp3, Hi, Tmp3);
|
2006-04-11 01:31:51 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
}
|
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case Promote:
|
2005-01-15 22:16:26 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // ret void
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
default: { // ret <values>
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> NewValues;
|
2005-01-07 07:47:09 +00:00
|
|
|
NewValues.push_back(Tmp1);
|
2006-05-26 23:09:09 +00:00
|
|
|
for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2)
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(i).getValueType())) {
|
|
|
|
case Legal:
|
2005-01-08 19:27:05 +00:00
|
|
|
NewValues.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-05-26 23:09:09 +00:00
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
case Expand: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(!Node->getOperand(i).getValueType().isExtended() &&
|
2006-04-11 02:00:08 +00:00
|
|
|
"FIXME: TODO: implement returning non-legal vector types!");
|
2005-01-07 07:47:09 +00:00
|
|
|
ExpandOp(Node->getOperand(i), Lo, Hi);
|
|
|
|
NewValues.push_back(Lo);
|
2006-05-26 23:09:09 +00:00
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Hi.getNode()) {
|
2006-12-11 19:27:14 +00:00
|
|
|
NewValues.push_back(Hi);
|
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
case Promote:
|
2005-01-15 22:16:26 +00:00
|
|
|
assert(0 && "Can't promote multiple return value yet!");
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
if (NewValues.size() == Node->getNumOperands())
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size());
|
2006-01-28 10:58:55 +00:00
|
|
|
else
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, dl, MVT::Other,
|
2006-08-08 01:09:31 +00:00
|
|
|
&NewValues[0], NewValues.size());
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-06 00:41:43 +00:00
|
|
|
|
2006-01-29 21:02:23 +00:00
|
|
|
if (Result.getOpcode() == ISD::RET) {
|
|
|
|
switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-29 21:02:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-06 00:41:43 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
case ISD::STORE: {
|
2006-10-13 21:14:26 +00:00
|
|
|
StoreSDNode *ST = cast<StoreSDNode>(Node);
|
|
|
|
Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer.
|
2007-07-09 22:18:38 +00:00
|
|
|
int SVOffset = ST->getSrcValueOffset();
|
|
|
|
unsigned Alignment = ST->getAlignment();
|
|
|
|
bool isVolatile = ST->isVolatile();
|
2006-10-13 21:14:26 +00:00
|
|
|
|
|
|
|
if (!ST->isTruncatingStore()) {
|
2006-12-12 04:18:56 +00:00
|
|
|
// Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr'
|
|
|
|
// FIXME: We shouldn't do this for TargetConstantFP's.
|
|
|
|
// FIXME: move this to the DAG Combiner! Note that we can't regress due
|
|
|
|
// to phase ordering between legalized code and the dag combiner. This
|
|
|
|
// probably means that we need to integrate dag combiner and legalizer
|
|
|
|
// together.
|
2007-09-14 22:26:36 +00:00
|
|
|
// We generally can't do this one for long doubles.
|
2007-10-13 06:35:54 +00:00
|
|
|
if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) {
|
2009-02-17 22:15:04 +00:00
|
|
|
if (CFP->getValueType(0) == MVT::f32 &&
|
2007-10-15 05:46:06 +00:00
|
|
|
getTypeAction(MVT::i32) == Legal) {
|
2008-03-11 00:11:06 +00:00
|
|
|
Tmp3 = DAG.getConstant(CFP->getValueAPF().
|
2008-10-09 18:53:47 +00:00
|
|
|
bitcastToAPInt().zextOrTrunc(32),
|
2007-09-11 18:32:33 +00:00
|
|
|
MVT::i32);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-09-14 22:26:36 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
|
|
|
break;
|
|
|
|
} else if (CFP->getValueType(0) == MVT::f64) {
|
2007-10-15 05:46:06 +00:00
|
|
|
// If this target supports 64-bit registers, do a single 64-bit store.
|
|
|
|
if (getTypeAction(MVT::i64) == Legal) {
|
2008-10-09 18:53:47 +00:00
|
|
|
Tmp3 = DAG.getConstant(CFP->getValueAPF().bitcastToAPInt().
|
2008-03-11 00:11:06 +00:00
|
|
|
zextOrTrunc(64), MVT::i64);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-10-15 05:46:06 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
|
|
|
break;
|
Disable some DAG combiner optimizations that may be
wrong for volatile loads and stores. In fact this
is almost all of them! There are three types of
problems: (1) it is wrong to change the width of
a volatile memory access. These may be used to
do memory mapped i/o, in which case a load can have
an effect even if the result is not used. Consider
loading an i32 but only using the lower 8 bits. It
is wrong to change this into a load of an i8, because
you are no longer tickling the other three bytes. It
is also unwise to make a load/store wider. For
example, changing an i16 load into an i32 load is
wrong no matter how aligned things are, since the
fact of loading an additional 2 bytes can have
i/o side-effects. (2) it is wrong to change the
number of volatile load/stores: they may be counted
by the hardware. (3) it is wrong to change a volatile
load/store that requires one memory access into one
that requires several. For example on x86-32, you
can store a double in one processor operation, but to
store an i64 requires two (two i32 stores). In a
multi-threaded program you may want to bitcast an i64
to a double and store as a double because that will
occur atomically, and be indivisible to other threads.
So it would be wrong to convert the store-of-double
into a store of an i64, because this will become two
i32 stores - no longer atomic. My policy here is
to say that the number of processor operations for
an illegal operation is undefined. So it is alright
to change a store of an i64 (requires at least two
stores; but could be validly lowered to memcpy for
example) into a store of double (one processor op).
In short, if the new store is legal and has the same
size then I say that the transform is ok. It would
also be possible to say that transforms are always
ok if before they were illegal, whether after they
are illegal or not, but that's more awkward to do
and I doubt it buys us anything much.
However this exposed an interesting thing - on x86-32
a store of i64 is considered legal! That is because
operations are marked legal by default, regardless of
whether the type is legal or not. In some ways this
is clever: before type legalization this means that
operations on illegal types are considered legal;
after type legalization there are no illegal types
so now operations are only legal if they really are.
But I consider this to be too cunning for mere mortals.
Better to do things explicitly by testing AfterLegalize.
So I have changed things so that operations with illegal
types are considered illegal - indeed they can never
map to a machine operation. However this means that
the DAG combiner is more conservative because before
it was "accidentally" performing transforms where the
type was illegal because the operation was nonetheless
marked legal. So in a few such places I added a check
on AfterLegalize, which I suppose was actually just
forgotten before. This causes the DAG combiner to do
slightly more than it used to, which resulted in the X86
backend blowing up because it got a slightly surprising
node it wasn't expecting, so I tweaked it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52254 91177308-0d34-0410-b5e6-96231b3b80d8
2008-06-13 19:07:40 +00:00
|
|
|
} else if (getTypeAction(MVT::i32) == Legal && !ST->isVolatile()) {
|
2007-10-15 05:46:06 +00:00
|
|
|
// Otherwise, if the target supports 32-bit registers, use 2 32-bit
|
|
|
|
// stores. If the target supports neither 32- nor 64-bits, this
|
|
|
|
// xform is certainly not worth it.
|
2008-10-09 18:53:47 +00:00
|
|
|
const APInt &IntVal =CFP->getValueAPF().bitcastToAPInt();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32);
|
|
|
|
SDValue Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32);
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian()) std::swap(Lo, Hi);
|
2007-10-15 05:46:06 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Lo = DAG.getStore(Tmp1, dl, Lo, Tmp2, ST->getSrcValue(),
|
2007-10-15 05:46:06 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(4));
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getStore(Tmp1, dl, Hi, Tmp2, ST->getSrcValue(), SVOffset+4,
|
2007-10-28 12:59:45 +00:00
|
|
|
isVolatile, MinAlign(Alignment, 4U));
|
2007-10-15 05:46:06 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
|
2007-10-15 05:46:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-12 04:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-01-30 00:15:11 +00:00
|
|
|
switch (getTypeAction(ST->getMemoryVT())) {
|
2006-10-13 21:14:26 +00:00
|
|
|
case Legal: {
|
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2,
|
2006-10-13 21:14:26 +00:00
|
|
|
ST->getOffset());
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Tmp3.getValueType();
|
2006-10-13 21:14:26 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::STORE, VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2007-08-01 19:34:21 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned store and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-06-06 12:08:01 +00:00
|
|
|
getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
|
2007-08-01 19:34:21 +00:00
|
|
|
if (ST->getAlignment() < ABIAlignment)
|
2008-08-28 21:40:38 +00:00
|
|
|
Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG,
|
2007-08-01 19:34:21 +00:00
|
|
|
TLI);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-13 21:14:26 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-10-13 21:14:26 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(VT.isVector() && "Unknown legal promote case!");
|
2009-02-17 22:15:04 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::BIT_CONVERT, dl,
|
2006-10-13 21:14:26 +00:00
|
|
|
TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2,
|
2007-07-09 22:18:38 +00:00
|
|
|
ST->getSrcValue(), SVOffset, isVolatile,
|
|
|
|
Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-16 01:36:45 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2006-10-13 21:14:26 +00:00
|
|
|
case Promote:
|
2008-10-30 08:01:45 +00:00
|
|
|
if (!ST->getMemoryVT().isVector()) {
|
|
|
|
// Truncate the value and store the result.
|
|
|
|
Tmp3 = PromoteOp(ST->getValue());
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-10-30 08:01:45 +00:00
|
|
|
SVOffset, ST->getMemoryVT(),
|
|
|
|
isVolatile, Alignment);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fall thru to expand for vector
|
|
|
|
case Expand: {
|
2006-10-13 21:14:26 +00:00
|
|
|
unsigned IncrementSize = 0;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-10-13 21:14:26 +00:00
|
|
|
// If this is a vector type, then we have to calculate the increment as
|
|
|
|
// the product of the element size in bytes, and the number of elements
|
|
|
|
// in the high half of the vector.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (ST->getValue().getValueType().isVector()) {
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *InVal = ST->getValue().getNode();
|
2008-08-26 22:36:50 +00:00
|
|
|
int InIx = ST->getValue().getResNo();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT InVT = InVal->getValueType(InIx);
|
|
|
|
unsigned NumElems = InVT.getVectorNumElements();
|
|
|
|
MVT EVT = InVT.getVectorElementType();
|
2006-10-13 21:14:26 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
2007-02-15 03:39:18 +00:00
|
|
|
// type. If so, convert to the vector type.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT TVT = MVT::getVectorVT(EVT, NumElems);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-02-15 03:39:18 +00:00
|
|
|
// Turn this into a normal store of the vector type.
|
2008-02-15 18:11:59 +00:00
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a normal store of the scalar type.
|
2008-02-15 18:11:59 +00:00
|
|
|
Tmp3 = ScalarizeVectorOp(ST->getValue());
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
// The scalarized value type may not be legal, e.g. it might require
|
|
|
|
// promotion or expansion. Relegalize the scalar store.
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
} else {
|
2008-10-30 08:01:45 +00:00
|
|
|
// Check if we have widen this node with another value
|
|
|
|
std::map<SDValue, SDValue>::iterator I =
|
|
|
|
WidenNodes.find(ST->getValue());
|
|
|
|
if (I != WidenNodes.end()) {
|
|
|
|
Result = StoreWidenVectorOp(ST, Tmp1, Tmp2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SplitVectorOp(ST->getValue(), Lo, Hi);
|
|
|
|
IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() *
|
|
|
|
EVT.getSizeInBits()/8;
|
|
|
|
}
|
2006-10-13 21:14:26 +00:00
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
} else {
|
2008-02-15 18:11:59 +00:00
|
|
|
ExpandOp(ST->getValue(), Lo, Hi);
|
2008-08-28 21:40:38 +00:00
|
|
|
IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0;
|
2006-10-13 21:14:26 +00:00
|
|
|
|
2008-09-25 16:15:10 +00:00
|
|
|
if (Hi.getNode() && TLI.isBigEndian())
|
2006-10-13 21:14:26 +00:00
|
|
|
std::swap(Lo, Hi);
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Lo = DAG.getStore(Tmp1, dl, Lo, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-12-12 19:53:13 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Hi.getNode() == NULL) {
|
2006-12-12 19:53:13 +00:00
|
|
|
// Must be int <-> float one-to-one expansion.
|
|
|
|
Result = Lo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2006-10-13 21:14:26 +00:00
|
|
|
assert(isTypeLegal(Tmp2.getValueType()) &&
|
|
|
|
"Pointers must be legal!");
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getStore(Tmp1, dl, Hi, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
|
2006-10-13 21:14:26 +00:00
|
|
|
break;
|
2008-10-30 08:01:45 +00:00
|
|
|
} // case Expand
|
2006-10-13 21:14:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-01-17 19:59:44 +00:00
|
|
|
switch (getTypeAction(ST->getValue().getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
|
|
|
break;
|
|
|
|
case Promote:
|
2008-10-30 08:01:45 +00:00
|
|
|
if (!ST->getValue().getValueType().isVector()) {
|
|
|
|
// We can promote the value, the truncstore will still take care of it.
|
|
|
|
Tmp3 = PromoteOp(ST->getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Vector case falls through to expand
|
2008-01-17 19:59:44 +00:00
|
|
|
case Expand:
|
|
|
|
// Just store the low part. This may become a non-trunc store, so make
|
|
|
|
// sure to use getTruncStore, not UpdateNodeOperands below.
|
|
|
|
ExpandOp(ST->getValue(), Tmp3, Tmp4);
|
2009-02-02 23:46:53 +00:00
|
|
|
return DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-17 19:59:44 +00:00
|
|
|
SVOffset, MVT::i8, isVolatile, Alignment);
|
|
|
|
}
|
2008-01-22 07:17:34 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT StVT = ST->getMemoryVT();
|
|
|
|
unsigned StWidth = StVT.getSizeInBits();
|
2008-01-22 07:17:34 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
if (StWidth != StVT.getStoreSizeInBits()) {
|
2008-01-22 07:17:34 +00:00
|
|
|
// Promote to a byte-sized store with upper bits zero if not
|
|
|
|
// storing an integral number of bytes. For example, promote
|
|
|
|
// TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1)
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NVT = MVT::getIntegerVT(StVT.getStoreSizeInBits());
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp3 = DAG.getZeroExtendInReg(Tmp3, dl, StVT);
|
|
|
|
Result = DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-22 07:17:34 +00:00
|
|
|
SVOffset, NVT, isVolatile, Alignment);
|
|
|
|
} else if (StWidth & (StWidth - 1)) {
|
|
|
|
// If not storing a power-of-2 number of bits, expand as two stores.
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(StVT.isExtended() && !StVT.isVector() &&
|
2008-01-22 07:17:34 +00:00
|
|
|
"Unsupported truncstore!");
|
|
|
|
unsigned RoundWidth = 1 << Log2_32(StWidth);
|
|
|
|
assert(RoundWidth < StWidth);
|
|
|
|
unsigned ExtraWidth = StWidth - RoundWidth;
|
|
|
|
assert(ExtraWidth < RoundWidth);
|
|
|
|
assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
|
|
|
|
"Store size not an integral number of bytes!");
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT RoundVT = MVT::getIntegerVT(RoundWidth);
|
|
|
|
MVT ExtraVT = MVT::getIntegerVT(ExtraWidth);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2008-01-22 07:17:34 +00:00
|
|
|
unsigned IncrementSize;
|
|
|
|
|
|
|
|
if (TLI.isLittleEndian()) {
|
|
|
|
// TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16)
|
|
|
|
// Store the bottom RoundWidth bits.
|
2009-02-02 23:46:53 +00:00
|
|
|
Lo = DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-22 07:17:34 +00:00
|
|
|
SVOffset, RoundVT,
|
|
|
|
isVolatile, Alignment);
|
|
|
|
|
|
|
|
// Store the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-22 07:17:34 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRL, dl, Tmp3.getValueType(), Tmp3,
|
2008-01-22 07:17:34 +00:00
|
|
|
DAG.getConstant(RoundWidth, TLI.getShiftAmountTy()));
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getTruncStore(Tmp1, dl, Hi, Tmp2, ST->getSrcValue(),
|
2008-01-22 07:17:34 +00:00
|
|
|
SVOffset + IncrementSize, ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
} else {
|
|
|
|
// Big endian - avoid unaligned stores.
|
|
|
|
// TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X
|
|
|
|
// Store the top RoundWidth bits.
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRL, dl, Tmp3.getValueType(), Tmp3,
|
2008-01-22 07:17:34 +00:00
|
|
|
DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy()));
|
2009-02-02 23:46:53 +00:00
|
|
|
Hi = DAG.getTruncStore(Tmp1, dl, Hi, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, RoundVT, isVolatile, Alignment);
|
2008-01-22 07:17:34 +00:00
|
|
|
|
|
|
|
// Store the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, dl, Tmp2.getValueType(), Tmp2,
|
2008-01-22 07:17:34 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2009-02-02 23:46:53 +00:00
|
|
|
Lo = DAG.getTruncStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-22 07:17:34 +00:00
|
|
|
SVOffset + IncrementSize, ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2008-01-22 07:17:34 +00:00
|
|
|
// The order of the stores doesn't matter.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo, Hi);
|
2008-01-22 07:17:34 +00:00
|
|
|
} else {
|
|
|
|
if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() ||
|
|
|
|
Tmp2 != ST->getBasePtr())
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2,
|
|
|
|
ST->getOffset());
|
|
|
|
|
|
|
|
switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned store and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-06-06 12:08:01 +00:00
|
|
|
getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
|
2008-01-22 07:17:34 +00:00
|
|
|
if (ST->getAlignment() < ABIAlignment)
|
2008-08-28 21:40:38 +00:00
|
|
|
Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.getNode()), DAG,
|
2008-01-22 07:17:34 +00:00
|
|
|
TLI);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
// TRUNCSTORE:i16 i32 -> STORE i16
|
|
|
|
assert(isTypeLegal(StVT) && "Do not know how to expand this store!");
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::TRUNCATE, dl, StVT, Tmp3);
|
|
|
|
Result = DAG.getStore(Tmp1, dl, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, isVolatile, Alignment);
|
2008-01-22 07:17:34 +00:00
|
|
|
break;
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
2006-10-13 21:14:26 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2005-03-31 21:24:06 +00:00
|
|
|
case ISD::PCMARKER:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-03-31 21:24:06 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
case ISD::STACKSAVE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-13 02:50:02 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode()) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
2006-01-13 02:50:02 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
case TargetLowering::Expand:
|
2009-02-17 22:15:04 +00:00
|
|
|
// Expand to CopyFromReg if the target set
|
2006-01-13 17:48:44 +00:00
|
|
|
// StackPointerRegisterToSaveRestore.
|
|
|
|
if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
|
2009-02-04 00:13:36 +00:00
|
|
|
Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), dl, SP,
|
2006-01-13 17:48:44 +00:00
|
|
|
Node->getValueType(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp2 = Tmp1.getValue(1);
|
2006-01-13 17:48:44 +00:00
|
|
|
} else {
|
2009-02-06 23:05:02 +00:00
|
|
|
Tmp1 = DAG.getUNDEF(Node->getValueType(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp2 = Node->getOperand(0);
|
2006-01-13 17:48:44 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Since stacksave produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp2 : Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2006-01-13 02:50:02 +00:00
|
|
|
case ISD::STACKRESTORE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-13 02:50:02 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-13 02:50:02 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2009-02-17 22:15:04 +00:00
|
|
|
// Expand to CopyToReg if the target set
|
2006-01-13 17:48:44 +00:00
|
|
|
// StackPointerRegisterToSaveRestore.
|
|
|
|
if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getCopyToReg(Tmp1, dl, SP, Tmp2);
|
2006-01-13 17:48:44 +00:00
|
|
|
} else {
|
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2006-01-13 02:50:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-11 16:47:30 +00:00
|
|
|
case ISD::READCYCLECOUNTER:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-11-29 08:26:18 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::READCYCLECOUNTER,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-11-29 19:13:47 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
|
|
|
break;
|
2006-11-29 08:26:18 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
2006-11-29 19:13:47 +00:00
|
|
|
Tmp1 = LegalizeOp(Result.getValue(0));
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
2006-11-29 08:26:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-02 04:56:24 +00:00
|
|
|
|
|
|
|
// Since rdcc produce two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp2);
|
2006-01-28 10:58:55 +00:00
|
|
|
return Result;
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2005-01-14 22:08:15 +00:00
|
|
|
case ISD::SELECT:
|
2005-01-18 19:27:06 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "It's impossible to expand bools");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition.
|
|
|
|
break;
|
2008-02-25 21:11:39 +00:00
|
|
|
case Promote: {
|
2008-10-30 08:01:45 +00:00
|
|
|
assert(!Node->getOperand(0).getValueType().isVector() && "not possible");
|
2005-01-18 19:27:06 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition.
|
2006-11-28 01:03:30 +00:00
|
|
|
// Make sure the condition is either zero or one.
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned BitWidth = Tmp1.getValueSizeInBits();
|
2007-06-22 14:59:07 +00:00
|
|
|
if (!DAG.MaskedValueIsZero(Tmp1,
|
2008-02-25 21:11:39 +00:00
|
|
|
APInt::getHighBitsSet(BitWidth, BitWidth-1)))
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, MVT::i1);
|
2005-01-18 19:27:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal
|
2005-01-14 22:08:15 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal
|
2005-01-16 07:29:19 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-08-23 04:29:48 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) {
|
2005-01-16 07:29:19 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom: {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-10 20:51:12 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
if (Tmp1.getOpcode() == ISD::SETCC) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getSelectCC(dl, Tmp1.getOperand(0), Tmp1.getOperand(1),
|
2005-08-10 20:51:12 +00:00
|
|
|
Tmp2, Tmp3,
|
|
|
|
cast<CondCodeSDNode>(Tmp1.getOperand(2))->get());
|
|
|
|
} else {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getSelectCC(dl, Tmp1,
|
2005-08-10 20:51:12 +00:00
|
|
|
DAG.getConstant(0, Tmp1.getValueType()),
|
|
|
|
Tmp2, Tmp3, ISD::SETNE);
|
|
|
|
}
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NVT =
|
2005-01-16 07:29:19 +00:00
|
|
|
TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType());
|
|
|
|
unsigned ExtOp, TruncOp;
|
2008-06-06 12:08:01 +00:00
|
|
|
if (Tmp2.getValueType().isVector()) {
|
2006-04-12 16:33:18 +00:00
|
|
|
ExtOp = ISD::BIT_CONVERT;
|
|
|
|
TruncOp = ISD::BIT_CONVERT;
|
2008-06-06 12:08:01 +00:00
|
|
|
} else if (Tmp2.getValueType().isInteger()) {
|
2006-01-28 07:39:30 +00:00
|
|
|
ExtOp = ISD::ANY_EXTEND;
|
|
|
|
TruncOp = ISD::TRUNCATE;
|
2005-01-16 07:29:19 +00:00
|
|
|
} else {
|
2006-01-28 07:39:30 +00:00
|
|
|
ExtOp = ISD::FP_EXTEND;
|
|
|
|
TruncOp = ISD::FP_ROUND;
|
2005-01-16 07:29:19 +00:00
|
|
|
}
|
|
|
|
// Promote each of the values to the new type.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getNode(ExtOp, dl, NVT, Tmp2);
|
|
|
|
Tmp3 = DAG.getNode(ExtOp, dl, NVT, Tmp3);
|
2005-01-16 07:29:19 +00:00
|
|
|
// Perform the larger operation, then round down.
|
2009-04-10 18:48:47 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NVT, Tmp1, Tmp2, Tmp3);
|
2008-01-17 07:00:52 +00:00
|
|
|
if (TruncOp != ISD::FP_ROUND)
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(TruncOp, dl, Node->getValueType(0), Result);
|
2008-01-17 07:00:52 +00:00
|
|
|
else
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(TruncOp, dl, Node->getValueType(0), Result,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(0));
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2006-02-01 07:19:44 +00:00
|
|
|
case ISD::SELECT_CC: {
|
|
|
|
Tmp1 = Node->getOperand(0); // LHS
|
|
|
|
Tmp2 = Node->getOperand(1); // RHS
|
2005-08-10 20:51:12 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // True
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // False
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CC = Node->getOperand(4);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
LegalizeSetCC(TLI.getSetCCResultType(Tmp1.getValueType()),
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1, Tmp2, CC, dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-15 02:05:31 +00:00
|
|
|
// If we didn't get both a LHS and RHS back from LegalizeSetCC,
|
2006-02-01 07:19:44 +00:00
|
|
|
// the LHS is a legal SETCC itself. In this case, we need to compare
|
|
|
|
// the result against zero to select between true and false values.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp2.getNode() == 0) {
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
|
|
|
|
CC = DAG.getCondCode(ISD::SETNE);
|
|
|
|
}
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC);
|
|
|
|
|
|
|
|
// Everything is legal, see if we should expand this op or something.
|
|
|
|
switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-02-01 07:19:44 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::SETCC:
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
|
|
|
Tmp2 = Node->getOperand(1);
|
|
|
|
Tmp3 = Node->getOperand(2);
|
2009-02-02 20:41:04 +00:00
|
|
|
LegalizeSetCC(Node->getValueType(0), Tmp1, Tmp2, Tmp3, dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// If we had to Expand the SetCC operands into a SELECT node, then it may
|
|
|
|
// not always be possible to return a true LHS & RHS. In this case, just
|
2006-02-01 07:19:44 +00:00
|
|
|
// return the value we legalized, returned in the LHS
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp2.getNode() == 0) {
|
2006-02-01 07:19:44 +00:00
|
|
|
Result = Tmp1;
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
|
2006-01-30 22:43:50 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) {
|
2006-01-28 07:39:30 +00:00
|
|
|
default: assert(0 && "Cannot handle this action for SETCC yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH.
|
|
|
|
case TargetLowering::Legal:
|
2006-12-15 02:59:56 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp4.getNode()) Result = Tmp4;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
break;
|
2005-11-30 17:12:26 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// First step, figure out the appropriate operation to use.
|
|
|
|
// Allow SETCC to not be supported for all legal data types
|
|
|
|
// Mostly this targets FP
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewInTy = Node->getOperand(0).getValueType();
|
|
|
|
MVT OldVT = NewInTy; OldVT = OldVT;
|
2005-11-30 17:12:26 +00:00
|
|
|
|
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
2008-06-06 12:08:01 +00:00
|
|
|
NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1);
|
2005-11-30 17:12:26 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(NewInTy.isInteger() == OldVT.isInteger() &&
|
2005-11-30 17:12:26 +00:00
|
|
|
"Fell off of the edge of the integer world");
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(NewInTy.isFloatingPoint() == OldVT.isFloatingPoint() &&
|
2005-11-30 17:12:26 +00:00
|
|
|
"Fell off of the edge of the floating point world");
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-11-30 17:12:26 +00:00
|
|
|
// If the target supports SETCC of this type, use it.
|
2009-01-28 17:46:25 +00:00
|
|
|
if (TLI.isOperationLegalOrCustom(ISD::SETCC, NewInTy))
|
2005-11-30 17:12:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-06-06 12:08:01 +00:00
|
|
|
if (NewInTy.isInteger())
|
2005-11-30 17:12:26 +00:00
|
|
|
assert(0 && "Cannot promote Legal Integer SETCC yet");
|
|
|
|
else {
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::FP_EXTEND, dl, NewInTy, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::FP_EXTEND, dl, NewInTy, Tmp2);
|
2005-11-30 17:12:26 +00:00
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-12-15 02:59:56 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-17 19:47:13 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2005-08-29 20:46:51 +00:00
|
|
|
break;
|
2005-11-30 17:12:26 +00:00
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
// Expand a setcc node into a select_cc of the same condition, lhs, and
|
|
|
|
// rhs that selects between const 1 (true) and const 0 (false).
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Tmp1, Tmp2,
|
2005-08-23 04:29:48 +00:00
|
|
|
DAG.getConstant(1, VT), DAG.getConstant(0, VT),
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp3);
|
2005-08-23 04:29:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2008-05-12 19:40:03 +00:00
|
|
|
case ISD::VSETCC: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CC = Node->getOperand(2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-05-12 19:40:03 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC);
|
|
|
|
|
|
|
|
// Everything is legal, see if we should expand this op or something.
|
|
|
|
switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2008-05-12 19:40:03 +00:00
|
|
|
break;
|
2008-12-13 08:15:14 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
// Unroll into a nasty set of scalar code for now.
|
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
unsigned NumElems = VT.getVectorNumElements();
|
|
|
|
MVT EltVT = VT.getVectorElementType();
|
|
|
|
MVT TmpEltVT = Tmp1.getValueType().getVectorElementType();
|
|
|
|
SmallVector<SDValue, 8> Ops(NumElems);
|
|
|
|
for (unsigned i = 0; i < NumElems; ++i) {
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue In1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, TmpEltVT,
|
2008-12-13 08:15:14 +00:00
|
|
|
Tmp1, DAG.getIntPtrConstant(i));
|
2009-02-02 23:46:53 +00:00
|
|
|
Ops[i] = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(TmpEltVT),
|
|
|
|
In1, DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl,
|
|
|
|
TmpEltVT, Tmp2,
|
|
|
|
DAG.getIntPtrConstant(i)),
|
2008-12-17 08:49:47 +00:00
|
|
|
CC);
|
2009-04-10 18:48:47 +00:00
|
|
|
Ops[i] = DAG.getNode(ISD::SELECT, dl, EltVT, Ops[i],
|
|
|
|
DAG.getConstant(APInt::getAllOnesValue
|
|
|
|
(EltVT.getSizeInBits()), EltVT),
|
|
|
|
DAG.getConstant(0, EltVT));
|
2008-12-13 08:15:14 +00:00
|
|
|
}
|
2009-02-25 22:49:59 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_VECTOR, dl, VT, &Ops[0], NumElems);
|
2008-12-13 08:15:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-05-12 19:40:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 20:23:03 +00:00
|
|
|
|
2005-04-02 04:00:59 +00:00
|
|
|
case ISD::SHL_PARTS:
|
|
|
|
case ISD::SRA_PARTS:
|
|
|
|
case ISD::SRL_PARTS: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2005-01-20 18:52:28 +00:00
|
|
|
bool Changed = false;
|
2009-01-31 15:50:11 +00:00
|
|
|
unsigned N = Node->getNumOperands();
|
|
|
|
for (unsigned i = 0; i + 1 < N; ++i) {
|
2005-01-20 18:52:28 +00:00
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
|
|
|
Changed |= Ops.back() != Node->getOperand(i);
|
|
|
|
}
|
2009-01-31 15:50:11 +00:00
|
|
|
Ops.push_back(LegalizeOp(DAG.getShiftAmountOperand(Node->getOperand(N-1))));
|
|
|
|
Changed |= Ops.back() != Node->getOperand(N-1);
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Changed)
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-04-02 05:00:07 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(),
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp2, RetVal(0, 0);
|
2006-01-09 18:31:59 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) {
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp2 = LegalizeOp(Tmp1.getValue(i));
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, i), Tmp2);
|
2008-08-26 22:36:50 +00:00
|
|
|
if (i == Op.getResNo())
|
2006-01-19 04:54:52 +00:00
|
|
|
RetVal = Tmp2;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(RetVal.getNode() && "Illegal result number");
|
2006-01-09 18:31:59 +00:00
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
// Since these produce multiple values, make sure to remember that we
|
|
|
|
// legalized all of them.
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, i), Result.getValue(i));
|
2008-08-26 22:36:50 +00:00
|
|
|
return Result.getValue(Op.getResNo());
|
2005-01-20 18:52:28 +00:00
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
|
|
|
|
// Binary operators
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
2005-04-11 03:01:51 +00:00
|
|
|
case ISD::MULHS:
|
|
|
|
case ISD::MULHU:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
2005-01-07 21:45:56 +00:00
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRL:
|
|
|
|
case ISD::SRA:
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::FDIV:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
2009-01-31 15:50:11 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
|
|
|
|
|
|
|
if ((Node->getOpcode() == ISD::SHL ||
|
|
|
|
Node->getOpcode() == ISD::SRL ||
|
|
|
|
Node->getOpcode() == ISD::SRA) &&
|
|
|
|
!Node->getValueType(0).isVector())
|
|
|
|
Tmp2 = DAG.getShiftAmountOperand(Tmp2);
|
|
|
|
|
|
|
|
switch (getTypeAction(Tmp2.getValueType())) {
|
2005-07-05 19:52:39 +00:00
|
|
|
case Expand: assert(0 && "Not possible");
|
|
|
|
case Legal:
|
2009-01-31 15:50:11 +00:00
|
|
|
Tmp2 = LegalizeOp(Tmp2); // Legalize the RHS.
|
2005-07-05 19:52:39 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
2009-01-31 15:50:11 +00:00
|
|
|
Tmp2 = PromoteOp(Tmp2); // Promote the RHS.
|
2005-07-05 19:52:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-29 15:49:41 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2008-11-10 04:46:22 +00:00
|
|
|
|
2005-12-24 23:42:32 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-04-02 03:57:31 +00:00
|
|
|
default: assert(0 && "BinOp legalize operation not supported");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) {
|
2008-07-29 15:49:41 +00:00
|
|
|
Result = Tmp1;
|
|
|
|
break;
|
2008-07-29 19:07:27 +00:00
|
|
|
}
|
2008-07-29 15:49:41 +00:00
|
|
|
// Fall through if the custom lower can't deal with the operation
|
2006-04-02 03:57:31 +00:00
|
|
|
case TargetLowering::Expand: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-10-08 18:33:35 +00:00
|
|
|
// See if multiply or divide can be lowered using two-result operations.
|
|
|
|
SDVTList VTs = DAG.getVTList(VT, VT);
|
|
|
|
if (Node->getOpcode() == ISD::MUL) {
|
|
|
|
// We just need the low half of the multiply; try both the signed
|
|
|
|
// and unsigned forms. If the target supports both SMUL_LOHI and
|
|
|
|
// UMUL_LOHI, form a preference by checking which forms of plain
|
|
|
|
// MULH it supports.
|
2009-01-28 17:46:25 +00:00
|
|
|
bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, VT);
|
|
|
|
bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, VT);
|
|
|
|
bool HasMULHS = TLI.isOperationLegalOrCustom(ISD::MULHS, VT);
|
|
|
|
bool HasMULHU = TLI.isOperationLegalOrCustom(ISD::MULHU, VT);
|
2007-10-08 18:33:35 +00:00
|
|
|
unsigned OpToUse = 0;
|
|
|
|
if (HasSMUL_LOHI && !HasMULHS) {
|
|
|
|
OpToUse = ISD::SMUL_LOHI;
|
|
|
|
} else if (HasUMUL_LOHI && !HasMULHU) {
|
|
|
|
OpToUse = ISD::UMUL_LOHI;
|
|
|
|
} else if (HasSMUL_LOHI) {
|
|
|
|
OpToUse = ISD::SMUL_LOHI;
|
|
|
|
} else if (HasUMUL_LOHI) {
|
|
|
|
OpToUse = ISD::UMUL_LOHI;
|
|
|
|
}
|
|
|
|
if (OpToUse) {
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = SDValue(DAG.getNode(OpToUse, dl, VTs, Tmp1, Tmp2).getNode(),
|
|
|
|
0);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::MULHS &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, VT)) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
VTs, Tmp1, Tmp2).getNode(),
|
2008-10-04 21:27:46 +00:00
|
|
|
1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
if (Node->getOpcode() == ISD::MULHU &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, VT)) {
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, dl,
|
|
|
|
VTs, Tmp1, Tmp2).getNode(),
|
2008-10-04 21:27:46 +00:00
|
|
|
1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::SDIV &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::SDIVREM, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
VTs, Tmp1, Tmp2).getNode(),
|
2008-10-04 21:27:46 +00:00
|
|
|
0);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::UDIV &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) {
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::UDIVREM, dl,
|
|
|
|
VTs, Tmp1, Tmp2).getNode(),
|
2008-10-04 21:27:46 +00:00
|
|
|
0);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-18 20:03:17 +00:00
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
// Check to see if we have a libcall for this operator.
|
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
|
|
|
bool isSigned = false;
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::SDIV:
|
|
|
|
if (VT == MVT::i32) {
|
|
|
|
LC = Node->getOpcode() == ISD::UDIV
|
2008-10-30 08:01:45 +00:00
|
|
|
? RTLIB::UDIV_I32 : RTLIB::SDIV_I32;
|
2007-10-11 23:57:53 +00:00
|
|
|
isSigned = Node->getOpcode() == ISD::SDIV;
|
|
|
|
}
|
|
|
|
break;
|
2008-10-04 21:27:46 +00:00
|
|
|
case ISD::MUL:
|
|
|
|
if (VT == MVT::i32)
|
|
|
|
LC = RTLIB::MUL_I32;
|
2009-01-24 22:12:48 +00:00
|
|
|
else if (VT == MVT::i64)
|
2008-12-29 03:21:37 +00:00
|
|
|
LC = RTLIB::MUL_I64;
|
2008-10-04 21:27:46 +00:00
|
|
|
break;
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80,
|
|
|
|
RTLIB::POW_PPCF128);
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::FDIV:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::DIV_F32, RTLIB::DIV_F64, RTLIB::DIV_F80,
|
|
|
|
RTLIB::DIV_PPCF128);
|
|
|
|
break;
|
2007-10-11 23:57:53 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
if (LC != RTLIB::UNKNOWN_LIBCALL) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, isSigned, Dummy);
|
2006-09-18 21:49:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(Node->getValueType(0).isVector() &&
|
2006-04-02 03:57:31 +00:00
|
|
|
"Cannot expand this binary operator!");
|
|
|
|
// Expand the operation into a bunch of nasty scalar code.
|
2007-10-11 23:57:53 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
2006-04-02 03:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-12 21:20:24 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: assert(0 && "Do not know how to promote this BinOp!");
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OVT = Node->getValueType(0);
|
|
|
|
MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
|
|
|
assert(OVT.isVector() && "Cannot promote this BinOp!");
|
2006-04-12 21:20:24 +00:00
|
|
|
// Bit convert each of the values to the new type.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Tmp2);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2006-04-12 21:20:24 +00:00
|
|
|
// Bit convert the result back the original type.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, OVT, Result);
|
2006-04-12 21:20:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-24 23:42:32 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-10-05 14:17:22 +00:00
|
|
|
case ISD::SMUL_LOHI:
|
|
|
|
case ISD::UMUL_LOHI:
|
|
|
|
case ISD::SDIVREM:
|
|
|
|
case ISD::UDIVREM:
|
|
|
|
// These nodes will only be produced by target-specific lowering, so
|
|
|
|
// they shouldn't be here if they aren't legal.
|
2007-10-16 09:07:20 +00:00
|
|
|
assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) &&
|
2007-10-05 14:17:22 +00:00
|
|
|
"This must be legal!");
|
2007-10-08 18:33:35 +00:00
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-10-05 14:17:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-05 05:09:38 +00:00
|
|
|
case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type!
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Not possible");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS.
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS.
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-05 05:09:38 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-05 05:09:38 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "Operation not supported");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-03-13 06:08:38 +00:00
|
|
|
break;
|
2006-03-05 05:09:38 +00:00
|
|
|
case TargetLowering::Legal: break;
|
2007-01-04 21:56:39 +00:00
|
|
|
case TargetLowering::Expand: {
|
2007-01-05 23:33:44 +00:00
|
|
|
// If this target supports fabs/fneg natively and select is cheap,
|
|
|
|
// do this efficiently.
|
|
|
|
if (!TLI.isSelectExpensive() &&
|
|
|
|
TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) ==
|
|
|
|
TargetLowering::Legal &&
|
2007-01-04 21:56:39 +00:00
|
|
|
TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) ==
|
2007-01-05 23:33:44 +00:00
|
|
|
TargetLowering::Legal) {
|
2006-03-13 06:08:38 +00:00
|
|
|
// Get the sign bit of the RHS.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT IVT =
|
2006-03-13 06:08:38 +00:00
|
|
|
Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64;
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue SignBit = DAG.getNode(ISD::BIT_CONVERT, dl, IVT, Tmp2);
|
|
|
|
SignBit = DAG.getSetCC(dl, TLI.getSetCCResultType(IVT),
|
2006-03-13 06:08:38 +00:00
|
|
|
SignBit, DAG.getConstant(0, IVT), ISD::SETLT);
|
|
|
|
// Get the absolute value of the result.
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue AbsVal = DAG.getNode(ISD::FABS, dl, Tmp1.getValueType(), Tmp1);
|
2006-03-13 06:08:38 +00:00
|
|
|
// Select between the nabs and abs value based on the sign bit of
|
|
|
|
// the input.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, AbsVal.getValueType(), SignBit,
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::FNEG, dl, AbsVal.getValueType(),
|
2006-03-13 06:08:38 +00:00
|
|
|
AbsVal),
|
|
|
|
AbsVal);
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-13 06:08:38 +00:00
|
|
|
// Otherwise, do bitwise ops!
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NVT =
|
2007-01-04 21:56:39 +00:00
|
|
|
Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64;
|
|
|
|
Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), Result);
|
2007-01-04 21:56:39 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2006-03-05 05:09:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
}
|
2006-03-05 05:09:38 +00:00
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-02-17 05:43:56 +00:00
|
|
|
case ISD::ADDC:
|
|
|
|
case ISD::SUBC:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2008-11-26 11:19:00 +00:00
|
|
|
Tmp3 = Result.getValue(0);
|
|
|
|
Tmp4 = Result.getValue(1);
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp3, DAG);
|
|
|
|
if (Tmp1.getNode() != NULL) {
|
2008-11-27 05:58:04 +00:00
|
|
|
Tmp3 = LegalizeOp(Tmp1);
|
2008-11-26 11:19:00 +00:00
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-02-17 05:43:56 +00:00
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2008-11-26 11:19:00 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp3);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp4);
|
|
|
|
return Op.getResNo() ? Tmp4 : Tmp3;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-02-17 05:43:56 +00:00
|
|
|
case ISD::ADDE:
|
|
|
|
case ISD::SUBE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2008-11-26 11:19:00 +00:00
|
|
|
Tmp3 = Result.getValue(0);
|
|
|
|
Tmp4 = Result.getValue(1);
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp3, DAG);
|
|
|
|
if (Tmp1.getNode() != NULL) {
|
2008-11-27 05:58:04 +00:00
|
|
|
Tmp3 = LegalizeOp(Tmp1);
|
2008-11-26 11:19:00 +00:00
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-02-17 05:43:56 +00:00
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2008-11-26 11:19:00 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Tmp3);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp4);
|
|
|
|
return Op.getResNo() ? Tmp4 : Tmp3;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-10-18 00:27:41 +00:00
|
|
|
case ISD::BUILD_PAIR: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PairTy = Node->getValueType(0);
|
2005-10-18 00:27:41 +00:00
|
|
|
// TODO: handle the case where the Lo and Hi operands are not of legal type
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi
|
|
|
|
switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
assert(0 && "Cannot promote/custom this yet!");
|
2005-10-18 00:27:41 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1))
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_PAIR, dl, PairTy, Tmp1, Tmp2);
|
2005-10-18 00:27:41 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, PairTy, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::ANY_EXTEND, dl, PairTy, Tmp2);
|
|
|
|
Tmp2 = DAG.getNode(ISD::SHL, dl, PairTy, Tmp2,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(PairTy.getSizeInBits()/2,
|
2005-10-18 00:27:41 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, dl, PairTy, Tmp1, Tmp2);
|
2005-10-18 00:27:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-06 00:23:54 +00:00
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::SREM:
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FREM:
|
2005-04-06 00:23:54 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2005-04-06 00:23:54 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote: assert(0 && "Cannot promote this yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2005-12-25 01:07:37 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
2005-12-25 01:07:37 +00:00
|
|
|
break;
|
2007-10-08 18:33:35 +00:00
|
|
|
case TargetLowering::Expand: {
|
2006-09-18 23:28:33 +00:00
|
|
|
unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV;
|
2006-12-31 05:55:36 +00:00
|
|
|
bool isSigned = DivOpc == ISD::SDIV;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-10-08 18:33:35 +00:00
|
|
|
// See if remainder can be lowered using two-result operations.
|
|
|
|
SDVTList VTs = DAG.getVTList(VT, VT);
|
|
|
|
if (Node->getOpcode() == ISD::SREM &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::SDIVREM, VT)) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::SDIVREM, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
VTs, Tmp1, Tmp2).getNode(), 1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::UREM &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::UDIVREM, VT)) {
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = SDValue(DAG.getNode(ISD::UDIVREM, dl,
|
|
|
|
VTs, Tmp1, Tmp2).getNode(), 1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isInteger()) {
|
2007-10-08 18:33:35 +00:00
|
|
|
if (TLI.getOperationAction(DivOpc, VT) ==
|
2006-09-18 21:49:04 +00:00
|
|
|
TargetLowering::Legal) {
|
|
|
|
// X % Y -> X-X/Y*Y
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(DivOpc, dl, VT, Tmp1, Tmp2);
|
|
|
|
Result = DAG.getNode(ISD::MUL, dl, VT, Result, Tmp2);
|
|
|
|
Result = DAG.getNode(ISD::SUB, dl, VT, Tmp1, Result);
|
2008-06-06 12:08:01 +00:00
|
|
|
} else if (VT.isVector()) {
|
2007-11-05 23:35:22 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
2006-09-18 21:49:04 +00:00
|
|
|
} else {
|
2007-10-08 18:33:35 +00:00
|
|
|
assert(VT == MVT::i32 &&
|
2006-09-18 21:49:04 +00:00
|
|
|
"Cannot expand this binary operator!");
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM
|
|
|
|
? RTLIB::UREM_I32 : RTLIB::SREM_I32;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, isSigned, Dummy);
|
2006-09-18 21:49:04 +00:00
|
|
|
}
|
2007-11-06 22:11:54 +00:00
|
|
|
} else {
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(VT.isFloatingPoint() &&
|
2007-11-06 22:11:54 +00:00
|
|
|
"remainder op must have integer or floating-point type");
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isVector()) {
|
2007-11-05 23:35:22 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
} else {
|
|
|
|
// Floating point mod -> fmod libcall.
|
2008-01-10 10:28:30 +00:00
|
|
|
RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64,
|
|
|
|
RTLIB::REM_F80, RTLIB::REM_PPCF128);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2007-11-05 23:35:22 +00:00
|
|
|
}
|
2005-04-06 00:23:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-08 18:33:35 +00:00
|
|
|
}
|
2005-04-06 00:23:54 +00:00
|
|
|
break;
|
2006-01-25 18:21:52 +00:00
|
|
|
case ISD::VAARG: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2006-01-25 18:21:52 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
Result = Result.getValue(0);
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Result.getValue(1);
|
|
|
|
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp2 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp2.getNode()) {
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = LegalizeOp(Tmp2);
|
|
|
|
Tmp1 = LegalizeOp(Tmp2.getValue(1));
|
|
|
|
}
|
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand: {
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue VAList = DAG.getLoad(TLI.getPointerTy(), dl, Tmp1, Tmp2, V, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
// Increment the pointer, VAList, to the next vaarg
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), VAList,
|
2009-01-12 20:38:59 +00:00
|
|
|
DAG.getConstant(TLI.getTargetData()->
|
|
|
|
getTypePaddedSize(VT.getTypeForMVT()),
|
|
|
|
TLI.getPointerTy()));
|
2006-01-25 18:21:52 +00:00
|
|
|
// Store the incremented VAList to the legalized pointer
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp3 = DAG.getStore(VAList.getValue(1), dl, Tmp3, Tmp2, V, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
// Load the actual argument out of the pointer VAList
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getLoad(VT, dl, Tmp3, VAList, NULL, 0);
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = LegalizeOp(Result.getValue(1));
|
2006-01-25 18:21:52 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
// Since VAARG produces two values, make sure to remember that we
|
2006-01-25 18:21:52 +00:00
|
|
|
// legalized both of them.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp1);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp1 : Result;
|
2006-01-25 18:21:52 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
case ISD::VACOPY:
|
2006-01-25 18:21:52 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer.
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3,
|
|
|
|
Node->getOperand(3), Node->getOperand(4));
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// This defaults to loading a pointer from the input and storing it to the
|
|
|
|
// output, returning the chain.
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue();
|
|
|
|
const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue();
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp4 = DAG.getLoad(TLI.getPointerTy(), dl, Tmp1, Tmp3, VS, 0);
|
|
|
|
Result = DAG.getStore(Tmp4.getValue(1), dl, Tmp4, Tmp2, VD, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
case ISD::VAEND:
|
2006-01-25 18:21:52 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp1, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = Tmp1; // Default to a no-op, return the chain
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
case ISD::VASTART:
|
2006-01-25 18:21:52 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-25 18:21:52 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-11 21:21:00 +00:00
|
|
|
case ISD::ROTL:
|
|
|
|
case ISD::ROTR:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
2009-01-31 15:50:11 +00:00
|
|
|
Tmp2 = LegalizeOp(DAG.getShiftAmountOperand(Node->getOperand(1))); // RHS
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-04-02 21:36:32 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default:
|
|
|
|
assert(0 && "ROTL/ROTR legalize operation not supported");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2007-04-02 21:36:32 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
assert(0 && "Do not know how to promote ROTL/ROTR");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
assert(0 && "Do not know how to expand ROTL/ROTR");
|
|
|
|
break;
|
|
|
|
}
|
2006-01-11 21:21:00 +00:00
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Op
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
assert(0 && "Cannot custom legalize this yet!");
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OVT = Tmp1.getValueType();
|
|
|
|
MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
|
|
|
unsigned DiffBits = NVT.getSizeInBits() - OVT.getSizeInBits();
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Tmp1);
|
|
|
|
Tmp1 = DAG.getNode(ISD::BSWAP, dl, NVT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SRL, dl, NVT, Tmp1,
|
2006-01-28 07:39:30 +00:00
|
|
|
DAG.getConstant(DiffBits, TLI.getShiftAmountTy()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = ExpandBSWAP(Tmp1, dl);
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2006-01-14 03:14:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-05-03 17:19:30 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Op
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2007-07-30 21:00:31 +00:00
|
|
|
case TargetLowering::Custom:
|
2005-05-03 17:19:30 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2007-07-30 21:00:31 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
|
2007-08-02 02:22:46 +00:00
|
|
|
TargetLowering::Custom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) {
|
2007-08-02 02:22:46 +00:00
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2007-07-30 21:00:31 +00:00
|
|
|
}
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT OVT = Tmp1.getValueType();
|
|
|
|
MVT NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
2005-05-11 04:51:16 +00:00
|
|
|
|
|
|
|
// Zero extend the argument.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Tmp1);
|
2005-05-03 17:19:30 +00:00
|
|
|
// Perform the larger operation, then subtract if needed.
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp1 = DAG.getNode(Node->getOpcode(), dl, Node->getValueType(0), Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2005-05-03 17:19:30 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case ISD::CTTZ:
|
|
|
|
//if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT)
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(Tmp1.getValueType()),
|
|
|
|
Tmp1, DAG.getConstant(NVT.getSizeInBits(), NVT),
|
2005-08-09 20:20:18 +00:00
|
|
|
ISD::SETEQ);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NVT, Tmp2,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(OVT.getSizeInBits(), NVT), Tmp1);
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
case ISD::CTLZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SUB, dl, NVT, Tmp1,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(NVT.getSizeInBits() -
|
|
|
|
OVT.getSizeInBits(), NVT));
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = ExpandBitCount(Node->getOpcode(), Tmp1, dl);
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
// Unary operators
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FNEG:
|
2005-04-28 21:44:33 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2008-08-21 17:55:02 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
case ISD::FCEIL:
|
|
|
|
case ISD::FRINT:
|
|
|
|
case ISD::FNEARBYINT:
|
2005-04-02 05:00:07 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
case TargetLowering::Custom:
|
2006-01-31 18:14:25 +00:00
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2005-04-02 05:00:07 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-31 18:14:25 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-31 18:14:25 +00:00
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2006-01-28 07:39:30 +00:00
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
case ISD::FNEG:
|
2005-04-02 05:00:07 +00:00
|
|
|
// Expand Y = FNEG(X) -> Y = SUB -0.0, X
|
|
|
|
Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::FSUB, dl, Node->getValueType(0), Tmp2, Tmp1);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
case ISD::FABS: {
|
2005-04-02 05:26:37 +00:00
|
|
|
// Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X).
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2005-04-02 05:26:37 +00:00
|
|
|
Tmp2 = DAG.getConstantFP(0.0, VT);
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(Tmp1.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
Tmp1, Tmp2, ISD::SETUGT);
|
2009-02-02 23:46:53 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::FNEG, dl, VT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, VT, Tmp2, Tmp1, Tmp3);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-09 23:35:53 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
2009-02-17 22:15:04 +00:00
|
|
|
case ISD::FCOS:
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2008-08-21 18:38:14 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
case ISD::FCEIL:
|
|
|
|
case ISD::FRINT:
|
2008-09-09 23:35:53 +00:00
|
|
|
case ISD::FNEARBYINT: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-10-11 23:57:53 +00:00
|
|
|
|
|
|
|
// Expand unsupported unary vector operators by unrolling them.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isVector()) {
|
2007-10-11 23:57:53 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2005-04-30 04:43:14 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FSQRT:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
|
|
|
|
RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSIN:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64,
|
|
|
|
RTLIB::SIN_F80, RTLIB::SIN_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FCOS:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64,
|
|
|
|
RTLIB::COS_F80, RTLIB::COS_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64,
|
|
|
|
RTLIB::LOG_F80, RTLIB::LOG_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FLOG2:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64,
|
|
|
|
RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FLOG10:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64,
|
|
|
|
RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FEXP:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64,
|
|
|
|
RTLIB::EXP_F80, RTLIB::EXP_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FEXP2:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64,
|
|
|
|
RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128);
|
|
|
|
break;
|
2008-08-21 18:38:14 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
|
|
|
|
RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
|
|
|
|
RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FCEIL:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64,
|
|
|
|
RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FRINT:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64,
|
|
|
|
RTLIB::RINT_F80, RTLIB::RINT_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FNEARBYINT:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64,
|
|
|
|
RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128);
|
|
|
|
break;
|
2008-09-09 23:35:53 +00:00
|
|
|
break;
|
2005-04-30 04:43:14 +00:00
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-09 06:03:30 +00:00
|
|
|
case ISD::FPOWI: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-10-11 23:57:53 +00:00
|
|
|
|
|
|
|
// Expand unsupported unary vector operators by unrolling them.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (VT.isVector()) {
|
2007-10-11 23:57:53 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always lower FPOWI into a libcall. No target support for it yet.
|
2008-01-10 10:28:30 +00:00
|
|
|
RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64,
|
|
|
|
RTLIB::POWI_F80, RTLIB::POWI_PPCF128);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2006-09-09 06:03:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT:
|
2006-01-23 07:30:46 +00:00
|
|
|
if (!isTypeLegal(Node->getOperand(0).getValueType())) {
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getValueType(0), dl);
|
2008-06-06 12:08:01 +00:00
|
|
|
} else if (Op.getOperand(0).getValueType().isVector()) {
|
2007-06-25 16:23:39 +00:00
|
|
|
// The input has to be a vector type, we have to either scalarize it, pack
|
|
|
|
// it, or convert it based on whether the input vector type is legal.
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *InVal = Node->getOperand(0).getNode();
|
2008-08-26 22:36:50 +00:00
|
|
|
int InIx = Node->getOperand(0).getResNo();
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements();
|
|
|
|
MVT EVT = InVal->getValueType(InIx).getVectorElementType();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
|
|
|
// type. If so, convert to the vector type.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT TVT = MVT::getVectorVT(EVT, NumElems);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-07-16 14:29:03 +00:00
|
|
|
// Turn this into a bit convert of the vector input.
|
2009-04-29 22:47:44 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0), Tmp1);
|
2007-06-25 16:23:39 +00:00
|
|
|
break;
|
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a bit convert of the scalar input.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, Node->getValueType(0),
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Node->getOperand(0)));
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// FIXME: UNIMP! Store then reload
|
|
|
|
assert(0 && "Cast from unsupported vector type not implemented yet!");
|
|
|
|
}
|
2006-01-23 07:30:46 +00:00
|
|
|
} else {
|
2005-12-23 00:16:34 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::BIT_CONVERT,
|
|
|
|
Node->getOperand(0).getValueType())) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Expand:
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getValueType(0), dl);
|
2005-12-23 00:16:34 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-12-23 00:16:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CONVERT_RNDSAT: {
|
|
|
|
ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode();
|
|
|
|
switch (CvtCode) {
|
|
|
|
default: assert(0 && "Unknown cvt code!");
|
|
|
|
case ISD::CVT_SF:
|
|
|
|
case ISD::CVT_UF:
|
|
|
|
case ISD::CVT_FF:
|
2008-12-09 07:27:39 +00:00
|
|
|
break;
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CVT_FS:
|
|
|
|
case ISD::CVT_FU:
|
|
|
|
case ISD::CVT_SS:
|
|
|
|
case ISD::CVT_SU:
|
|
|
|
case ISD::CVT_US:
|
|
|
|
case ISD::CVT_UU: {
|
|
|
|
SDValue DTyOp = Node->getOperand(1);
|
|
|
|
SDValue STyOp = Node->getOperand(2);
|
|
|
|
SDValue RndOp = Node->getOperand(3);
|
|
|
|
SDValue SatOp = Node->getOperand(4);
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, DTyOp, STyOp,
|
|
|
|
RndOp, SatOp);
|
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
|
|
|
|
TargetLowering::Custom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
// For FP, make Op1 a i32
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getConvertRndSat(Op.getValueType(), dl, Result,
|
2008-11-10 20:54:11 +00:00
|
|
|
DTyOp, STyOp, RndOp, SatOp, CvtCode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // end switch CvtCode
|
|
|
|
break;
|
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
// Conversion operators. The source and destination have different types.
|
2005-07-28 23:31:12 +00:00
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP: {
|
|
|
|
bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP;
|
2008-08-14 20:04:46 +00:00
|
|
|
Result = LegalizeINT_TO_FP(Result, isSigned,
|
2009-02-02 19:03:57 +00:00
|
|
|
Node->getValueType(0), Node->getOperand(0), dl);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::TRUNCATE:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-12-02 19:55:08 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "Unknown TRUNCATE legalization operation action!");
|
|
|
|
case TargetLowering::Custom:
|
2008-12-11 00:44:22 +00:00
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2008-12-02 19:55:08 +00:00
|
|
|
case TargetLowering::Legal:
|
2008-12-11 00:44:22 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
|
|
|
}
|
|
|
|
break;
|
2008-12-12 01:25:51 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
assert(Result.getValueType().isVector() && "must be vector type");
|
|
|
|
// Unroll the truncate. We should do better.
|
|
|
|
Result = LegalizeOp(UnrollVectorOp(Result));
|
2008-12-02 12:12:25 +00:00
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
|
|
|
|
|
|
|
// Since the result is legal, we should just be able to truncate the low
|
|
|
|
// part of the source.
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), Tmp1);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, Op.getValueType(), Result);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2005-07-28 23:31:12 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2005-07-30 00:04:12 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
|
2005-07-29 00:11:56 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0),
|
2009-02-17 22:15:04 +00:00
|
|
|
Node->getOpcode() == ISD::FP_TO_SINT,
|
2009-02-02 19:03:57 +00:00
|
|
|
dl);
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2005-07-29 00:11:56 +00:00
|
|
|
case TargetLowering::Expand:
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
if (Node->getOpcode() == ISD::FP_TO_UINT) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue True, False;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getOperand(0).getValueType();
|
|
|
|
MVT NVT = Node->getValueType(0);
|
2007-09-19 23:55:34 +00:00
|
|
|
const uint64_t zero[] = {0, 0};
|
2008-06-06 12:08:01 +00:00
|
|
|
APFloat apf = APFloat(APInt(VT.getSizeInBits(), 2, zero));
|
|
|
|
APInt x = APInt::getSignBit(NVT.getSizeInBits());
|
2008-02-29 01:44:25 +00:00
|
|
|
(void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven);
|
2007-09-19 23:55:34 +00:00
|
|
|
Tmp2 = DAG.getConstantFP(apf, VT);
|
2009-02-17 22:15:04 +00:00
|
|
|
Tmp3 = DAG.getSetCC(dl, TLI.getSetCCResultType(VT),
|
2009-02-02 19:03:57 +00:00
|
|
|
Node->getOperand(0),
|
2009-01-01 15:52:00 +00:00
|
|
|
Tmp2, ISD::SETLT);
|
2009-02-02 19:03:57 +00:00
|
|
|
True = DAG.getNode(ISD::FP_TO_SINT, dl, NVT, Node->getOperand(0));
|
|
|
|
False = DAG.getNode(ISD::FP_TO_SINT, dl, NVT,
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::FSUB, dl, VT,
|
2009-02-02 19:03:57 +00:00
|
|
|
Node->getOperand(0), Tmp2));
|
|
|
|
False = DAG.getNode(ISD::XOR, dl, NVT, False,
|
2008-02-29 01:44:25 +00:00
|
|
|
DAG.getConstant(x, NVT));
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NVT, Tmp3, True, False);
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Do not know how to expand FP_TO_SINT yet!");
|
|
|
|
}
|
|
|
|
break;
|
2005-07-29 00:11:56 +00:00
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
2006-12-13 01:57:55 +00:00
|
|
|
case Expand: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT OVT = Node->getOperand(0).getValueType();
|
2007-10-11 23:32:15 +00:00
|
|
|
// Convert ppcf128 to i32
|
2007-10-10 01:01:31 +00:00
|
|
|
if (OVT == MVT::ppcf128 && VT == MVT::i32) {
|
2008-01-17 07:00:52 +00:00
|
|
|
if (Node->getOpcode() == ISD::FP_TO_SINT) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, MVT::ppcf128,
|
2008-01-17 07:00:52 +00:00
|
|
|
Node->getOperand(0), DAG.getValueType(MVT::f64));
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, dl, MVT::f64, Result,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(1));
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_TO_SINT, dl, VT, Result);
|
2008-01-17 07:00:52 +00:00
|
|
|
} else {
|
2007-10-11 23:32:15 +00:00
|
|
|
const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
|
|
|
|
APFloat apf = APFloat(APInt(128, 2, TwoE31));
|
|
|
|
Tmp2 = DAG.getConstantFP(apf, OVT);
|
|
|
|
// X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
|
|
|
|
// FIXME: generated code sucks.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, dl, VT, Node->getOperand(0),
|
2009-02-02 19:03:57 +00:00
|
|
|
Tmp2,
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32,
|
|
|
|
DAG.getNode(ISD::FP_TO_SINT, dl, VT,
|
|
|
|
DAG.getNode(ISD::FSUB, dl, OVT,
|
2007-10-11 23:32:15 +00:00
|
|
|
Node->getOperand(0), Tmp2)),
|
|
|
|
DAG.getConstant(0x80000000, MVT::i32)),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::FP_TO_SINT, dl, VT,
|
2007-10-11 23:32:15 +00:00
|
|
|
Node->getOperand(0)),
|
|
|
|
DAG.getCondCode(ISD::SETGE));
|
|
|
|
}
|
2007-10-10 01:01:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-10 23:03:31 +00:00
|
|
|
// Convert f32 / f64 to i32 / i64 / i128.
|
2008-07-17 02:36:29 +00:00
|
|
|
RTLIB::Libcall LC = (Node->getOpcode() == ISD::FP_TO_SINT) ?
|
|
|
|
RTLIB::getFPTOSINT(OVT, VT) : RTLIB::getFPTOUINT(OVT, VT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!");
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2006-12-13 01:57:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
case Promote:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1));
|
|
|
|
Result = LegalizeOp(Result);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2008-01-16 06:57:07 +00:00
|
|
|
case ISD::FP_EXTEND: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT DstVT = Op.getValueType();
|
|
|
|
MVT SrcVT = Op.getOperand(0).getValueType();
|
2008-01-17 07:00:52 +00:00
|
|
|
if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) {
|
|
|
|
// The only other way we can lower this is to turn it into a STORE,
|
|
|
|
// LOAD pair, targetting a temporary location (a stack slot).
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT, dl);
|
2008-01-17 07:00:52 +00:00
|
|
|
break;
|
2008-01-16 06:57:07 +00:00
|
|
|
}
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, dl, Op.getValueType(), Tmp1);
|
2008-01-16 06:57:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-17 07:00:52 +00:00
|
|
|
}
|
2007-08-09 01:04:01 +00:00
|
|
|
case ISD::FP_ROUND: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT DstVT = Op.getValueType();
|
|
|
|
MVT SrcVT = Op.getOperand(0).getValueType();
|
2008-01-17 07:00:52 +00:00
|
|
|
if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) {
|
|
|
|
if (SrcVT == MVT::ppcf128) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo;
|
2008-01-20 01:18:38 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Result);
|
2008-01-17 07:00:52 +00:00
|
|
|
// Round it the rest of the way (e.g. to f32) if needed.
|
2008-01-20 01:18:38 +00:00
|
|
|
if (DstVT!=MVT::f64)
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, dl,
|
|
|
|
DstVT, Result, Op.getOperand(1));
|
2008-01-17 07:00:52 +00:00
|
|
|
break;
|
2007-08-09 01:04:01 +00:00
|
|
|
}
|
2008-01-17 07:00:52 +00:00
|
|
|
// The only other way we can lower this is to turn it into a STORE,
|
|
|
|
// LOAD pair, targetting a temporary location (a stack slot).
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT, dl);
|
2008-01-17 07:00:52 +00:00
|
|
|
break;
|
2007-07-03 00:53:03 +00:00
|
|
|
}
|
2008-01-16 06:57:07 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-01-17 07:00:52 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2008-01-16 06:57:07 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, dl, Op.getValueType(), Tmp1,
|
2008-01-17 07:00:52 +00:00
|
|
|
Node->getOperand(1));
|
2008-01-16 06:57:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-17 07:00:52 +00:00
|
|
|
}
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
2005-01-07 07:47:09 +00:00
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-04-30 00:26:38 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2008-02-15 23:05:48 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
|
|
|
|
TargetLowering::Custom) {
|
2008-04-30 00:26:38 +00:00
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2008-02-15 23:05:48 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case Promote:
|
|
|
|
switch (Node->getOpcode()) {
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, dl, Op.getValueType(), Tmp1);
|
2005-09-02 00:18:10 +00:00
|
|
|
break;
|
2005-01-16 00:38:00 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, dl, Op.getValueType(), Result);
|
|
|
|
Result = DAG.getZeroExtendInReg(Result, dl,
|
2005-04-13 02:38:47 +00:00
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-15 05:21:40 +00:00
|
|
|
break;
|
|
|
|
case ISD::SIGN_EXTEND:
|
2005-01-16 00:38:00 +00:00
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, dl, Op.getValueType(), Result);
|
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Result.getValueType(),
|
2005-07-10 00:07:11 +00:00
|
|
|
Result,
|
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-01-16 00:38:00 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::FP_ROUND_INREG:
|
2005-04-13 02:38:47 +00:00
|
|
|
case ISD::SIGN_EXTEND_INREG: {
|
2005-01-15 06:18:18 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT();
|
2005-01-15 07:15:18 +00:00
|
|
|
|
|
|
|
// If this operation is not supported, convert it to a shl/shr or load/store
|
|
|
|
// pair.
|
2005-01-16 07:29:19 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2005-01-15 07:15:18 +00:00
|
|
|
// If this is an integer extend and shifts are supported, do that.
|
2005-04-13 02:38:47 +00:00
|
|
|
if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) {
|
2005-01-15 07:15:18 +00:00
|
|
|
// NOTE: we could fall back on load/store here too for targets without
|
|
|
|
// SAR. However, it is doubtful that any exist.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned BitsDiff = Node->getValueType(0).getSizeInBits() -
|
|
|
|
ExtraVT.getSizeInBits();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy());
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SHL, dl, Node->getValueType(0),
|
2005-01-15 07:15:18 +00:00
|
|
|
Node->getOperand(0), ShiftCst);
|
2009-02-02 23:46:53 +00:00
|
|
|
Result = DAG.getNode(ISD::SRA, dl, Node->getValueType(0),
|
2005-01-15 07:15:18 +00:00
|
|
|
Result, ShiftCst);
|
|
|
|
} else if (Node->getOpcode() == ISD::FP_ROUND_INREG) {
|
2006-10-11 17:52:19 +00:00
|
|
|
// The only way we can lower this is to turn it into a TRUNCSTORE,
|
2005-01-15 07:15:18 +00:00
|
|
|
// EXTLOAD pair, targetting a temporary location (a stack slot).
|
|
|
|
|
|
|
|
// NOTE: there is a choice here between constantly creating new stack
|
|
|
|
// slots and always reusing the same one. We currently always create
|
|
|
|
// new ones, as reuse may inhibit scheduling.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), ExtraVT,
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getValueType(0), dl);
|
2005-01-15 07:15:18 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown op");
|
|
|
|
}
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
2005-01-15 07:15:18 +00:00
|
|
|
}
|
2005-01-15 06:18:18 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2007-07-27 12:58:54 +00:00
|
|
|
case ISD::TRAMPOLINE: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[6];
|
2007-07-27 12:58:54 +00:00
|
|
|
for (unsigned i = 0; i != 6; ++i)
|
|
|
|
Ops[i] = LegalizeOp(Node->getOperand(i));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Ops, 6);
|
|
|
|
// The only option for this node is to custom lower it.
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode() && "Should always custom lower!");
|
2007-09-11 14:10:23 +00:00
|
|
|
|
|
|
|
// Since trampoline produces two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result.getValue(1));
|
|
|
|
Result = LegalizeOp(Result);
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 0), Result);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), Tmp1);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Op.getResNo() ? Tmp1 : Result;
|
2007-11-15 23:25:33 +00:00
|
|
|
}
|
2008-05-14 00:43:10 +00:00
|
|
|
case ISD::FLT_ROUNDS_: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2007-11-15 23:25:33 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2007-11-15 23:25:33 +00:00
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this operation is not supported, lower it to constant 1
|
|
|
|
Result = DAG.getConstant(1, VT);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-12 16:07:15 +00:00
|
|
|
break;
|
2008-01-15 07:02:33 +00:00
|
|
|
}
|
2008-01-15 21:58:08 +00:00
|
|
|
case ISD::TRAP: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
2008-01-15 07:02:33 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
2008-01-15 21:58:08 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
break;
|
2008-01-15 07:02:33 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) break;
|
2008-01-15 07:02:33 +00:00
|
|
|
// Fall Thru
|
2008-01-15 21:58:08 +00:00
|
|
|
case TargetLowering::Expand:
|
2008-01-15 07:02:33 +00:00
|
|
|
// If this operation is not supported, lower it to 'abort()' call
|
2008-01-15 21:58:08 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-01-15 07:02:33 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
2009-04-10 18:48:47 +00:00
|
|
|
std::pair<SDValue, SDValue> CallResult =
|
2008-02-14 17:28:50 +00:00
|
|
|
TLI.LowerCallTo(Tmp1, Type::VoidTy,
|
2008-09-26 19:31:26 +00:00
|
|
|
false, false, false, false, CallingConv::C, false,
|
2008-09-16 21:48:12 +00:00
|
|
|
DAG.getExternalSymbol("abort", TLI.getPointerTy()),
|
2009-01-30 23:10:59 +00:00
|
|
|
Args, DAG, dl);
|
2008-01-15 07:02:33 +00:00
|
|
|
Result = CallResult.second;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-15 21:58:08 +00:00
|
|
|
break;
|
2007-07-27 12:58:54 +00:00
|
|
|
}
|
2008-11-22 00:22:52 +00:00
|
|
|
|
2008-12-09 22:08:41 +00:00
|
|
|
case ISD::SADDO:
|
|
|
|
case ISD::SSUBO: {
|
2008-11-25 08:12:19 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.getNode()) break;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal: {
|
|
|
|
SDValue LHS = LegalizeOp(Node->getOperand(0));
|
|
|
|
SDValue RHS = LegalizeOp(Node->getOperand(1));
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::SADDO ?
|
2009-02-02 23:46:53 +00:00
|
|
|
ISD::ADD : ISD::SUB, dl, LHS.getValueType(),
|
2008-12-09 22:08:41 +00:00
|
|
|
LHS, RHS);
|
2008-11-25 08:12:19 +00:00
|
|
|
MVT OType = Node->getValueType(1);
|
|
|
|
|
2008-11-25 08:19:22 +00:00
|
|
|
SDValue Zero = DAG.getConstant(0, LHS.getValueType());
|
2008-11-25 08:12:19 +00:00
|
|
|
|
2008-11-25 19:40:17 +00:00
|
|
|
// LHSSign -> LHS >= 0
|
|
|
|
// RHSSign -> RHS >= 0
|
|
|
|
// SumSign -> Sum >= 0
|
|
|
|
//
|
2008-12-09 22:08:41 +00:00
|
|
|
// Add:
|
2008-11-25 19:40:17 +00:00
|
|
|
// Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign)
|
2008-12-09 22:08:41 +00:00
|
|
|
// Sub:
|
|
|
|
// Overflow -> (LHSSign != RHSSign) && (LHSSign != SumSign)
|
2008-11-25 19:40:17 +00:00
|
|
|
//
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue LHSSign = DAG.getSetCC(dl, OType, LHS, Zero, ISD::SETGE);
|
|
|
|
SDValue RHSSign = DAG.getSetCC(dl, OType, RHS, Zero, ISD::SETGE);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue SignsMatch = DAG.getSetCC(dl, OType, LHSSign, RHSSign,
|
|
|
|
Node->getOpcode() == ISD::SADDO ?
|
2008-12-09 22:08:41 +00:00
|
|
|
ISD::SETEQ : ISD::SETNE);
|
2008-11-25 19:40:17 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue SumSign = DAG.getSetCC(dl, OType, Sum, Zero, ISD::SETGE);
|
|
|
|
SDValue SumSignNE = DAG.getSetCC(dl, OType, LHSSign, SumSign, ISD::SETNE);
|
2008-11-25 19:40:17 +00:00
|
|
|
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue Cmp = DAG.getNode(ISD::AND, dl, OType, SignsMatch, SumSignNE);
|
2008-11-25 08:12:19 +00:00
|
|
|
|
|
|
|
MVT ValueVTs[] = { LHS.getValueType(), OType };
|
|
|
|
SDValue Ops[] = { Sum, Cmp };
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::MERGE_VALUES, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
DAG.getVTList(&ValueVTs[0], 2),
|
2008-12-01 11:41:29 +00:00
|
|
|
&Ops[0], 2);
|
2008-11-25 08:12:19 +00:00
|
|
|
SDNode *RNode = Result.getNode();
|
2009-04-15 20:06:30 +00:00
|
|
|
DAG.ReplaceAllUsesWith(Node, RNode);
|
2008-11-25 08:12:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2008-12-09 22:08:41 +00:00
|
|
|
case ISD::UADDO:
|
|
|
|
case ISD::USUBO: {
|
2008-11-24 19:21:46 +00:00
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.getNode()) break;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal: {
|
|
|
|
SDValue LHS = LegalizeOp(Node->getOperand(0));
|
|
|
|
SDValue RHS = LegalizeOp(Node->getOperand(1));
|
|
|
|
|
2008-12-09 22:08:41 +00:00
|
|
|
SDValue Sum = DAG.getNode(Node->getOpcode() == ISD::UADDO ?
|
2009-02-02 23:46:53 +00:00
|
|
|
ISD::ADD : ISD::SUB, dl, LHS.getValueType(),
|
2008-12-09 22:08:41 +00:00
|
|
|
LHS, RHS);
|
2008-11-24 19:21:46 +00:00
|
|
|
MVT OType = Node->getValueType(1);
|
2009-02-02 23:46:53 +00:00
|
|
|
SDValue Cmp = DAG.getSetCC(dl, OType, Sum, LHS,
|
2009-02-17 22:15:04 +00:00
|
|
|
Node->getOpcode () == ISD::UADDO ?
|
2008-12-09 22:08:41 +00:00
|
|
|
ISD::SETULT : ISD::SETUGT);
|
2008-11-24 19:21:46 +00:00
|
|
|
|
|
|
|
MVT ValueVTs[] = { LHS.getValueType(), OType };
|
|
|
|
SDValue Ops[] = { Sum, Cmp };
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::MERGE_VALUES, dl,
|
2009-02-02 23:46:53 +00:00
|
|
|
DAG.getVTList(&ValueVTs[0], 2),
|
2008-12-01 11:41:29 +00:00
|
|
|
&Ops[0], 2);
|
2008-11-24 19:21:46 +00:00
|
|
|
SDNode *RNode = Result.getNode();
|
2009-04-15 20:06:30 +00:00
|
|
|
DAG.ReplaceAllUsesWith(Node, RNode);
|
2008-11-24 19:21:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-22 00:22:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-09 22:08:41 +00:00
|
|
|
case ISD::SMULO:
|
|
|
|
case ISD::UMULO: {
|
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported at all!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.getNode()) break;
|
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// FIXME: According to Hacker's Delight, this can be implemented in
|
|
|
|
// target independent lowering, but it would be inefficient, since it
|
2008-12-10 02:01:32 +00:00
|
|
|
// requires a division + a branch.
|
2009-02-17 22:15:04 +00:00
|
|
|
assert(0 && "Target independent lowering is not supported for SMULO/UMULO!");
|
2008-12-09 22:08:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-15 07:15:18 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-04-08 04:13:17 +00:00
|
|
|
assert(Result.getValueType() == Op.getValueType() &&
|
|
|
|
"Bad legalization!");
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
// Make sure that the generated code is itself legal.
|
|
|
|
if (Result != Op)
|
|
|
|
Result = LegalizeOp(Result);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-05-12 16:53:42 +00:00
|
|
|
// Note that LegalizeOp may be reentered even from single-use nodes, which
|
|
|
|
// means that we always must cache transformed nodes.
|
|
|
|
AddLegalizedOperand(Op, Result);
|
2005-01-07 07:47:09 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
/// PromoteOp - Given an operation that produces a value in an invalid type,
|
|
|
|
/// promote it to compute the value into a larger type. The produced value will
|
|
|
|
/// have the correct bits for the low portion of the register, but no guarantee
|
|
|
|
/// is made about the top bits: it may be zero, sign-extended, or garbage.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::PromoteOp(SDValue Op) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT NVT = TLI.getTypeToTransformTo(VT);
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(getTypeAction(VT) == Promote &&
|
|
|
|
"Caller should expand or legalize operands that are not promotable!");
|
2008-06-08 20:54:56 +00:00
|
|
|
assert(NVT.bitsGT(VT) && NVT.isInteger() == VT.isInteger() &&
|
2005-01-15 05:21:40 +00:00
|
|
|
"Cannot promote to smaller type!");
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp1, Tmp2, Tmp3;
|
|
|
|
SDValue Result;
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-02 22:12:50 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2005-01-15 05:21:40 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, SDValue>::iterator I = PromotedNodes.find(Op);
|
2005-09-02 20:32:45 +00:00
|
|
|
if (I != PromotedNodes.end()) return I->second;
|
2005-05-12 16:53:42 +00:00
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2005-08-16 21:55:35 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
assert(0 && "CopyFromReg must be legal!");
|
2005-01-15 05:21:40 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(0 && "Do not know how to promote this operator!");
|
|
|
|
abort();
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF:
|
2009-02-06 23:05:02 +00:00
|
|
|
Result = DAG.getUNDEF(NVT);
|
2005-04-01 22:34:39 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::Constant:
|
2005-08-30 16:56:19 +00:00
|
|
|
if (VT != MVT::i1)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND, dl, NVT, Op);
|
2005-08-30 16:56:19 +00:00
|
|
|
else
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Op);
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?");
|
|
|
|
break;
|
|
|
|
case ISD::ConstantFP:
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Op);
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?");
|
|
|
|
break;
|
2005-01-18 17:54:55 +00:00
|
|
|
|
2009-01-01 15:52:00 +00:00
|
|
|
case ISD::SETCC: {
|
|
|
|
MVT VT0 = Node->getOperand(0).getValueType();
|
|
|
|
assert(isTypeLegal(TLI.getSetCCResultType(VT0))
|
2008-03-14 00:53:31 +00:00
|
|
|
&& "SetCC type is not legal??");
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SETCC, dl, TLI.getSetCCResultType(VT0),
|
2008-03-14 00:53:31 +00:00
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
|
|
|
Node->getOperand(2));
|
2005-01-18 02:59:52 +00:00
|
|
|
break;
|
2009-01-01 15:52:00 +00:00
|
|
|
}
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::TRUNCATE:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
2008-06-08 20:54:56 +00:00
|
|
|
assert(Result.getValueType().bitsGE(NVT) &&
|
2005-01-15 05:21:40 +00:00
|
|
|
"This truncation doesn't make sense!");
|
2008-06-08 20:54:56 +00:00
|
|
|
if (Result.getValueType().bitsGT(NVT)) // Truncate to NVT instead of VT
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, NVT, Result);
|
2005-01-15 05:21:40 +00:00
|
|
|
break;
|
2005-01-28 22:52:50 +00:00
|
|
|
case Promote:
|
|
|
|
// The truncation is not required, because we don't guarantee anything
|
|
|
|
// about high bits anyway.
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case Expand:
|
2005-04-04 00:57:08 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
|
|
|
// Truncate the low part of the expanded value to the result type
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, dl, NVT, Tmp1);
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-01-15 22:16:26 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "BUG: Smaller reg should have been promoted!");
|
|
|
|
case Legal:
|
|
|
|
// Input is legal? Just do extend all the way to the larger type.
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Node->getOperand(0));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
// Promote the reg if it's smaller.
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
// The high bits are not guaranteed to be anything. Insert an extend.
|
|
|
|
if (Node->getOpcode() == ISD::SIGN_EXTEND)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-09-02 00:18:10 +00:00
|
|
|
else if (Node->getOpcode() == ISD::ZERO_EXTEND)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getZeroExtendInReg(Result, dl,
|
2005-04-13 02:38:47 +00:00
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CONVERT_RNDSAT: {
|
|
|
|
ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode();
|
|
|
|
assert ((CvtCode == ISD::CVT_SS || CvtCode == ISD::CVT_SU ||
|
|
|
|
CvtCode == ISD::CVT_US || CvtCode == ISD::CVT_UU ||
|
|
|
|
CvtCode == ISD::CVT_SF || CvtCode == ISD::CVT_UF) &&
|
|
|
|
"can only promote integers");
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getConvertRndSat(NVT, dl, Node->getOperand(0),
|
2008-11-10 20:54:11 +00:00
|
|
|
Node->getOperand(1), Node->getOperand(2),
|
|
|
|
Node->getOperand(3), Node->getOperand(4),
|
|
|
|
CvtCode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT:
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getValueType(0), dl);
|
2005-12-23 00:16:34 +00:00
|
|
|
Result = PromoteOp(Result);
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::FP_EXTEND:
|
|
|
|
assert(0 && "Case not implemented. Dynamically dead with 2 FP types!");
|
|
|
|
case ISD::FP_ROUND:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "BUG: Cannot expand FP regs!");
|
|
|
|
case Promote: assert(0 && "Unreachable with 2 FP types!");
|
|
|
|
case Legal:
|
2008-01-17 07:00:52 +00:00
|
|
|
if (Node->getConstantOperandVal(1) == 0) {
|
|
|
|
// Input is legal? Do an FP_ROUND_INREG.
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Node->getOperand(0),
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getValueType(VT));
|
|
|
|
} else {
|
|
|
|
// Just remove the truncate, it isn't affecting the value.
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, dl, NVT, Node->getOperand(0),
|
2008-01-17 07:00:52 +00:00
|
|
|
Node->getOperand(1));
|
|
|
|
}
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2005-01-21 06:05:23 +00:00
|
|
|
// No extra round required here.
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Node->getOperand(0));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Promote:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
if (Node->getOpcode() == ISD::SINT_TO_FP)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Result.getValueType(),
|
2005-07-10 00:07:11 +00:00
|
|
|
Result,
|
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-01-15 22:16:26 +00:00
|
|
|
else
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getZeroExtendInReg(Result, dl,
|
2005-04-13 02:38:47 +00:00
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-21 06:05:23 +00:00
|
|
|
// No extra round required here.
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Result);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
2005-01-21 06:05:23 +00:00
|
|
|
Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT,
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getOperand(0), dl);
|
2005-01-21 06:05:23 +00:00
|
|
|
// Round if we cannot tolerate excess precision.
|
|
|
|
if (NoExcessFPPrecision)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2005-01-21 06:05:23 +00:00
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-09 17:32:47 +00:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Result,
|
2005-12-09 17:32:47 +00:00
|
|
|
Node->getOperand(1));
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2006-12-16 02:10:30 +00:00
|
|
|
case Expand:
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
// The input result is prerounded, so we don't have to do anything
|
|
|
|
// special.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
// If we're promoting a UINT to a larger size, check to see if the new node
|
|
|
|
// will be legal. If it isn't, check to see if FP_TO_SINT is legal, since
|
|
|
|
// we can use that instead. This allows us to generate better code for
|
|
|
|
// FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not
|
|
|
|
// legal, such as PowerPC.
|
2009-02-17 22:15:04 +00:00
|
|
|
if (Node->getOpcode() == ISD::FP_TO_UINT &&
|
2009-01-28 17:46:25 +00:00
|
|
|
!TLI.isOperationLegalOrCustom(ISD::FP_TO_UINT, NVT) &&
|
|
|
|
(TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NVT) ||
|
2005-10-25 23:47:25 +00:00
|
|
|
TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_TO_SINT, dl, NVT, Tmp1);
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1);
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
}
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FNEG:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
assert(Tmp1.getValueType() == NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1);
|
2005-04-02 05:00:07 +00:00
|
|
|
// NOTE: we do not have to do any extra rounding here for
|
|
|
|
// NoExcessFPPrecision, because we know the input will have the appropriate
|
|
|
|
// precision, and these operations don't modify precision at all.
|
|
|
|
break;
|
|
|
|
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2005-04-28 21:44:33 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
2008-08-21 18:38:14 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
case ISD::FCEIL:
|
|
|
|
case ISD::FRINT:
|
|
|
|
case ISD::FNEARBYINT:
|
2005-04-28 21:44:33 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
assert(Tmp1.getValueType() == NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (NoExcessFPPrecision)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2005-04-28 21:44:33 +00:00
|
|
|
break;
|
|
|
|
|
2008-09-09 23:35:53 +00:00
|
|
|
case ISD::FPOW:
|
2007-03-03 23:43:21 +00:00
|
|
|
case ISD::FPOWI: {
|
2008-09-09 23:35:53 +00:00
|
|
|
// Promote f32 pow(i) to f64 pow(i). Note that this could insert a libcall
|
2007-03-03 23:43:21 +00:00
|
|
|
// directly as well, which may be better.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2008-09-09 23:35:53 +00:00
|
|
|
Tmp2 = Node->getOperand(1);
|
|
|
|
if (Node->getOpcode() == ISD::FPOW)
|
|
|
|
Tmp2 = PromoteOp(Tmp2);
|
2007-03-03 23:43:21 +00:00
|
|
|
assert(Tmp1.getValueType() == NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2007-03-03 23:43:21 +00:00
|
|
|
if (NoExcessFPPrecision)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2007-03-03 23:43:21 +00:00
|
|
|
DAG.getValueType(VT));
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_CMP_SWAP: {
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node);
|
2008-02-21 06:45:13 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2));
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(3));
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getAtomic(Node->getOpcode(), dl, AtomNode->getMemoryVT(),
|
|
|
|
AtomNode->getChain(),
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomNode->getBasePtr(), Tmp2, Tmp3,
|
2008-06-25 16:07:49 +00:00
|
|
|
AtomNode->getSrcValue(),
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomNode->getAlignment());
|
2008-02-21 06:45:13 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_LOAD_ADD:
|
|
|
|
case ISD::ATOMIC_LOAD_SUB:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_NAND:
|
|
|
|
case ISD::ATOMIC_LOAD_MIN:
|
|
|
|
case ISD::ATOMIC_LOAD_MAX:
|
|
|
|
case ISD::ATOMIC_LOAD_UMIN:
|
|
|
|
case ISD::ATOMIC_LOAD_UMAX:
|
|
|
|
case ISD::ATOMIC_SWAP: {
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomicSDNode* AtomNode = cast<AtomicSDNode>(Node);
|
2008-02-21 06:45:13 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2));
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getAtomic(Node->getOpcode(), dl, AtomNode->getMemoryVT(),
|
2009-02-17 22:15:04 +00:00
|
|
|
AtomNode->getChain(),
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomNode->getBasePtr(), Tmp2,
|
2008-06-25 16:07:49 +00:00
|
|
|
AtomNode->getSrcValue(),
|
2008-06-25 08:15:39 +00:00
|
|
|
AtomNode->getAlignment());
|
2008-02-21 06:45:13 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::ADD:
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SUB:
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::MUL:
|
|
|
|
// The input may have strange things in the top bits of the registers, but
|
2005-09-28 22:28:18 +00:00
|
|
|
// these operations don't care. They may have weird bits going out, but
|
2005-01-15 06:18:18 +00:00
|
|
|
// that too is okay if they are integer operations.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2005-09-28 22:28:18 +00:00
|
|
|
break;
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-09-28 22:28:18 +00:00
|
|
|
// Floating point operations will give excess precision that we may not be
|
|
|
|
// able to tolerate. If we DO allow excess precision, just leave it,
|
|
|
|
// otherwise excise it.
|
2005-01-15 22:16:26 +00:00
|
|
|
// FIXME: Why would we need to round FP ops more than integer ones?
|
|
|
|
// Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C))
|
2005-09-28 22:28:18 +00:00
|
|
|
if (NoExcessFPPrecision)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2005-01-15 06:18:18 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::SREM:
|
|
|
|
// These operators require that their input be sign extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
2008-06-06 12:08:01 +00:00
|
|
|
if (NVT.isInteger()) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Tmp1,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Tmp2,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2005-01-15 22:16:26 +00:00
|
|
|
}
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2005-01-15 22:16:26 +00:00
|
|
|
|
|
|
|
// Perform FP_ROUND: this is probably overly pessimistic.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (NVT.isFloatingPoint() && NoExcessFPPrecision)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FDIV:
|
|
|
|
case ISD::FREM:
|
2006-03-05 05:09:38 +00:00
|
|
|
case ISD::FCOPYSIGN:
|
2005-09-28 22:28:18 +00:00
|
|
|
// These operators require that their input be fp extended.
|
2006-05-09 18:20:51 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
2008-01-17 07:00:52 +00:00
|
|
|
case Expand: assert(0 && "not implemented");
|
|
|
|
case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break;
|
2006-05-09 18:20:51 +00:00
|
|
|
}
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
2008-01-17 07:00:52 +00:00
|
|
|
case Expand: assert(0 && "not implemented");
|
|
|
|
case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break;
|
|
|
|
case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break;
|
2006-05-09 18:20:51 +00:00
|
|
|
}
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-09-28 22:28:18 +00:00
|
|
|
// Perform FP_ROUND: this is probably overly pessimistic.
|
2006-03-05 05:09:38 +00:00
|
|
|
if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN)
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, dl, NVT, Result,
|
2005-09-28 22:28:18 +00:00
|
|
|
DAG.getValueType(VT));
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::UREM:
|
|
|
|
// These operators require that their input be zero extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(NVT.isInteger() && "Operators don't apply to FP!");
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, VT);
|
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, dl, VT);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1, Tmp2);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::SHL:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SHL, dl, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case ISD::SRA:
|
|
|
|
// The input value must be properly sign extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Tmp1,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(VT));
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SRA, dl, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case ISD::SRL:
|
|
|
|
// The input value must be properly zero extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, VT);
|
|
|
|
Result = DAG.getNode(ISD::SRL, dl, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2006-01-28 03:14:31 +00:00
|
|
|
|
|
|
|
case ISD::VAARG:
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Node->getOperand(0); // Get the chain.
|
|
|
|
Tmp2 = Node->getOperand(1); // Get the pointer.
|
2006-01-28 03:14:31 +00:00
|
|
|
if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) {
|
2009-02-04 00:13:36 +00:00
|
|
|
Tmp3 = DAG.getVAArg(VT, dl, Tmp1, Tmp2, Node->getOperand(2));
|
2008-07-04 11:47:58 +00:00
|
|
|
Result = TLI.LowerOperation(Tmp3, DAG);
|
2006-01-28 03:14:31 +00:00
|
|
|
} else {
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
|
2009-02-04 00:13:36 +00:00
|
|
|
SDValue VAList = DAG.getLoad(TLI.getPointerTy(), dl, Tmp1, Tmp2, V, 0);
|
2006-01-28 03:14:31 +00:00
|
|
|
// Increment the pointer, VAList, to the next vaarg
|
2009-02-17 22:15:04 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), VAList,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(VT.getSizeInBits()/8,
|
2006-01-28 03:14:31 +00:00
|
|
|
TLI.getPointerTy()));
|
|
|
|
// Store the incremented VAList to the legalized pointer
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp3 = DAG.getStore(VAList.getValue(1), dl, Tmp3, Tmp2, V, 0);
|
2006-01-28 03:14:31 +00:00
|
|
|
// Load the actual argument out of the pointer VAList
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getExtLoad(ISD::EXTLOAD, dl, NVT, Tmp3, VAList, NULL, 0, VT);
|
2006-01-28 03:14:31 +00:00
|
|
|
}
|
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 07:39:30 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
2006-01-28 03:14:31 +00:00
|
|
|
break;
|
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
2006-10-10 07:51:21 +00:00
|
|
|
ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node)
|
|
|
|
? ISD::EXTLOAD : LD->getExtensionType();
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getExtLoad(ExtType, dl, NVT,
|
2006-10-10 07:51:21 +00:00
|
|
|
LD->getChain(), LD->getBasePtr(),
|
2006-10-10 18:54:19 +00:00
|
|
|
LD->getSrcValue(), LD->getSrcValueOffset(),
|
2008-01-30 00:15:11 +00:00
|
|
|
LD->getMemoryVT(),
|
2007-07-09 22:18:38 +00:00
|
|
|
LD->isVolatile(),
|
|
|
|
LD->getAlignment());
|
2005-10-13 20:07:41 +00:00
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 07:39:30 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
2005-10-13 20:07:41 +00:00
|
|
|
break;
|
2006-10-09 20:57:25 +00:00
|
|
|
}
|
2008-06-02 22:18:03 +00:00
|
|
|
case ISD::SELECT: {
|
2005-01-15 05:21:40 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1
|
2008-06-02 22:18:03 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT2 = Tmp2.getValueType();
|
2008-06-02 22:18:03 +00:00
|
|
|
assert(VT2 == Tmp3.getValueType()
|
2008-06-03 19:13:20 +00:00
|
|
|
&& "PromoteOp SELECT: Operands 2 and 3 ValueTypes don't match");
|
|
|
|
// Ensure that the resulting node is at least the same size as the operands'
|
|
|
|
// value types, because we cannot assume that TLI.getSetCCValueType() is
|
|
|
|
// constant.
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, VT2, Node->getOperand(0), Tmp2, Tmp3);
|
2005-01-15 05:21:40 +00:00
|
|
|
break;
|
2008-06-02 22:18:03 +00:00
|
|
|
}
|
2005-08-10 20:51:12 +00:00
|
|
|
case ISD::SELECT_CC:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2)); // True
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(3)); // False
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, dl, NVT, Node->getOperand(0),
|
2006-01-28 07:39:30 +00:00
|
|
|
Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4));
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP:
|
|
|
|
Tmp1 = Node->getOperand(0);
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Tmp1);
|
|
|
|
Tmp1 = DAG.getNode(ISD::BSWAP, dl, NVT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SRL, dl, NVT, Tmp1,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(NVT.getSizeInBits() -
|
|
|
|
VT.getSizeInBits(),
|
2006-01-14 03:14:10 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
|
|
|
break;
|
2005-05-04 19:11:05 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// Zero extend the argument
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Node->getOperand(0));
|
2005-05-04 19:11:05 +00:00
|
|
|
// Perform the larger operation, then subtract if needed.
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp1 = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2005-05-04 19:11:05 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case ISD::CTTZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT)
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(Tmp1.getValueType()), Tmp1,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(NVT.getSizeInBits(), NVT),
|
2007-05-18 17:52:13 +00:00
|
|
|
ISD::SETEQ);
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NVT, Tmp2,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(VT.getSizeInBits(), NVT), Tmp1);
|
2005-05-04 19:11:05 +00:00
|
|
|
break;
|
|
|
|
case ISD::CTLZ:
|
|
|
|
//Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
|
2009-02-02 22:12:50 +00:00
|
|
|
Result = DAG.getNode(ISD::SUB, dl, NVT, Tmp1,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(NVT.getSizeInBits() -
|
|
|
|
VT.getSizeInBits(), NVT));
|
2005-05-04 19:11:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
|
|
|
Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op));
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
2006-04-02 05:06:04 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
|
|
|
Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op));
|
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode() && "Didn't set a result!");
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Make sure the result is itself legal.
|
|
|
|
Result = LegalizeOp(Result);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
// Remember that we promoted this!
|
2005-01-15 05:21:40 +00:00
|
|
|
AddPromotedOperand(Op, Result);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into
|
|
|
|
/// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic,
|
|
|
|
/// based on the vector type. The return type of this matches the element type
|
|
|
|
/// of the vector, which may not be legal for the target.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDValue Op) {
|
2006-03-31 17:55:51 +00:00
|
|
|
// We know that operand #0 is the Vec vector. If the index is a constant
|
|
|
|
// or if the invec is a supported hardware type, we can use it. Otherwise,
|
|
|
|
// lower to a store then an indexed load.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Vec = Op.getOperand(0);
|
|
|
|
SDValue Idx = Op.getOperand(1);
|
2009-02-07 19:59:05 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT TVT = Vec.getValueType();
|
|
|
|
unsigned NumElems = TVT.getVectorNumElements();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom: {
|
|
|
|
Vec = LegalizeOp(Vec);
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp3 = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp3.getNode())
|
2007-06-25 16:23:39 +00:00
|
|
|
return Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (isTypeLegal(TVT)) {
|
|
|
|
Vec = LegalizeOp(Vec);
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-07-26 03:33:13 +00:00
|
|
|
return Op;
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-10-30 08:01:45 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
assert(TVT.isVector() && "not vector type");
|
|
|
|
// fall thru to expand since vectors are by default are promote
|
2007-06-25 16:23:39 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumElems == 1) {
|
2006-03-31 17:55:51 +00:00
|
|
|
// This must be an access of the only element. Return it.
|
2007-06-25 16:23:39 +00:00
|
|
|
Op = ScalarizeVectorOp(Vec);
|
|
|
|
} else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) {
|
2008-01-29 02:24:00 +00:00
|
|
|
unsigned NumLoElts = 1 << Log2_32(NumElems-1);
|
2007-06-25 16:23:39 +00:00
|
|
|
ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2006-03-31 17:55:51 +00:00
|
|
|
SplitVectorOp(Vec, Lo, Hi);
|
2008-09-12 16:56:44 +00:00
|
|
|
if (CIdx->getZExtValue() < NumLoElts) {
|
2006-03-31 17:55:51 +00:00
|
|
|
Vec = Lo;
|
|
|
|
} else {
|
|
|
|
Vec = Hi;
|
2008-09-12 16:56:44 +00:00
|
|
|
Idx = DAG.getConstant(CIdx->getZExtValue() - NumLoElts,
|
2007-06-25 16:23:39 +00:00
|
|
|
Idx.getValueType());
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-31 17:55:51 +00:00
|
|
|
// It's now an extract from the appropriate high or low part. Recurse.
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-06-25 16:23:39 +00:00
|
|
|
Op = ExpandEXTRACT_VECTOR_ELT(Op);
|
2006-03-31 17:55:51 +00:00
|
|
|
} else {
|
2007-06-25 16:23:39 +00:00
|
|
|
// Store the value to a temporary stack slot, then LOAD the scalar
|
|
|
|
// element back out.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StackPtr = DAG.CreateStackTemporary(Vec.getValueType());
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, NULL, 0);
|
2007-06-25 16:23:39 +00:00
|
|
|
|
|
|
|
// Add the offset to the index.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned EltSize = Op.getValueType().getSizeInBits()/8;
|
2009-02-02 20:41:04 +00:00
|
|
|
Idx = DAG.getNode(ISD::MUL, dl, Idx.getValueType(), Idx,
|
2007-06-25 16:23:39 +00:00
|
|
|
DAG.getConstant(EltSize, Idx.getValueType()));
|
2007-10-18 08:32:37 +00:00
|
|
|
|
2008-06-08 20:54:56 +00:00
|
|
|
if (Idx.getValueType().bitsGT(TLI.getPointerTy()))
|
2009-02-02 20:41:04 +00:00
|
|
|
Idx = DAG.getNode(ISD::TRUNCATE, dl, TLI.getPointerTy(), Idx);
|
2007-10-18 08:32:37 +00:00
|
|
|
else
|
2009-02-02 20:41:04 +00:00
|
|
|
Idx = DAG.getNode(ISD::ZERO_EXTEND, dl, TLI.getPointerTy(), Idx);
|
2007-10-18 08:32:37 +00:00
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
StackPtr = DAG.getNode(ISD::ADD, dl, Idx.getValueType(), Idx, StackPtr);
|
2007-06-25 16:23:39 +00:00
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
Op = DAG.getLoad(Op.getValueType(), dl, Ch, StackPtr, NULL, 0);
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
return Op;
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now
|
2007-06-13 15:12:02 +00:00
|
|
|
/// we assume the operation can be split if it is not already legal.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDValue Op) {
|
2007-06-13 15:12:02 +00:00
|
|
|
// We know that operand #0 is the Vec vector. For now we assume the index
|
|
|
|
// is a constant and that the extracted result is a supported hardware type.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Vec = Op.getOperand(0);
|
|
|
|
SDValue Idx = LegalizeOp(Op.getOperand(1));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumElems = Vec.getValueType().getVectorNumElements();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
if (NumElems == Op.getValueType().getVectorNumElements()) {
|
2007-06-13 15:12:02 +00:00
|
|
|
// This must be an access of the desired vector length. Return it.
|
2007-06-25 16:23:39 +00:00
|
|
|
return Vec;
|
2007-06-13 15:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo, Hi;
|
2007-06-13 15:12:02 +00:00
|
|
|
SplitVectorOp(Vec, Lo, Hi);
|
2008-09-12 16:56:44 +00:00
|
|
|
if (CIdx->getZExtValue() < NumElems/2) {
|
2007-06-13 15:12:02 +00:00
|
|
|
Vec = Lo;
|
|
|
|
} else {
|
|
|
|
Vec = Hi;
|
2008-09-12 16:56:44 +00:00
|
|
|
Idx = DAG.getConstant(CIdx->getZExtValue() - NumElems/2,
|
|
|
|
Idx.getValueType());
|
2007-06-13 15:12:02 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-13 15:12:02 +00:00
|
|
|
// It's now an extract from the appropriate high or low part. Recurse.
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-06-25 16:23:39 +00:00
|
|
|
return ExpandEXTRACT_SUBVECTOR(Op);
|
2006-04-02 05:06:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
/// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC
|
|
|
|
/// with condition CC on the current target. This usually involves legalizing
|
|
|
|
/// or promoting the arguments. In the case where LHS and RHS must be expanded,
|
|
|
|
/// there may be no choice but to create a new SetCC node to represent the
|
|
|
|
/// legalized value of setcc lhs, rhs. In this case, the value is returned in
|
2008-07-27 21:46:04 +00:00
|
|
|
/// LHS, and the SDValue returned in RHS has a nil SDNode value.
|
|
|
|
void SelectionDAGLegalize::LegalizeSetCCOperands(SDValue &LHS,
|
|
|
|
SDValue &RHS,
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue &CC,
|
|
|
|
DebugLoc dl) {
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue Tmp1, Tmp2, Tmp3, Result;
|
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
switch (getTypeAction(LHS.getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(LHS); // LHS
|
|
|
|
Tmp2 = LegalizeOp(RHS); // RHS
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(LHS); // LHS
|
|
|
|
Tmp2 = PromoteOp(RHS); // RHS
|
|
|
|
|
|
|
|
// If this is an FP compare, the operands have already been extended.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (LHS.getValueType().isInteger()) {
|
|
|
|
MVT VT = LHS.getValueType();
|
|
|
|
MVT NVT = TLI.getTypeToTransformTo(VT);
|
2006-02-01 07:19:44 +00:00
|
|
|
|
|
|
|
// Otherwise, we have to insert explicit sign or zero extends. Note
|
|
|
|
// that we could insert sign extends for ALL conditions, but zero extend
|
|
|
|
// is cheaper on many machines (an AND instead of two shifts), so prefer
|
|
|
|
// it.
|
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
default: assert(0 && "Unknown integer comparison!");
|
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETNE:
|
|
|
|
case ISD::SETUGE:
|
|
|
|
case ISD::SETUGT:
|
|
|
|
case ISD::SETULE:
|
|
|
|
case ISD::SETULT:
|
|
|
|
// ALL of these operations will work if we either sign or zero extend
|
|
|
|
// the operands (including the unsigned comparisons!). Zero extend is
|
|
|
|
// usually a simpler/cheaper operation, so prefer it.
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, VT);
|
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, dl, VT);
|
2006-02-01 07:19:44 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETLE:
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Tmp1,
|
2006-02-01 07:19:44 +00:00
|
|
|
DAG.getValueType(VT));
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Tmp2,
|
2006-02-01 07:19:44 +00:00
|
|
|
DAG.getValueType(VT));
|
2008-10-13 18:46:18 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1); // Relegalize new nodes.
|
|
|
|
Tmp2 = LegalizeOp(Tmp2); // Relegalize new nodes.
|
2006-02-01 07:19:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
case Expand: {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = LHS.getValueType();
|
2006-12-15 02:59:56 +00:00
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
|
|
|
// Expand into one or more soft-fp libcall(s).
|
2008-07-01 21:35:46 +00:00
|
|
|
RTLIB::Libcall LC1 = RTLIB::UNKNOWN_LIBCALL, LC2 = RTLIB::UNKNOWN_LIBCALL;
|
2006-12-15 02:59:56 +00:00
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETOEQ:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETNE:
|
|
|
|
case ISD::SETUNE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETOGE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETOLT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETLE:
|
|
|
|
case ISD::SETOLE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETOGT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETUO:
|
2007-01-31 09:29:11 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
case ISD::SETO:
|
2007-02-03 00:43:46 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
case ISD::SETONE:
|
|
|
|
// SETONE = SETOLT | SETOGT
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
// Fallthrough
|
|
|
|
case ISD::SETUGT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETUGE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETULT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETULE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::SETUEQ:
|
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
default: assert(0 && "Unsupported FP setcc!");
|
|
|
|
}
|
|
|
|
}
|
2008-06-30 10:19:09 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Dummy;
|
|
|
|
SDValue Ops[2] = { LHS, RHS };
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2, dl).getNode(),
|
2007-01-03 04:22:32 +00:00
|
|
|
false /*sign irrelevant*/, Dummy);
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp2 = DAG.getConstant(0, MVT::i32);
|
2007-01-31 09:29:11 +00:00
|
|
|
CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1));
|
2007-01-12 02:11:51 +00:00
|
|
|
if (LC2 != RTLIB::UNKNOWN_LIBCALL) {
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SETCC, dl,
|
2009-01-01 15:52:00 +00:00
|
|
|
TLI.getSetCCResultType(Tmp1.getValueType()),
|
|
|
|
Tmp1, Tmp2, CC);
|
2009-02-02 20:41:04 +00:00
|
|
|
LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2, dl).getNode(),
|
2007-01-03 04:22:32 +00:00
|
|
|
false /*sign irrelevant*/, Dummy);
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SETCC, dl,
|
2009-01-01 15:52:00 +00:00
|
|
|
TLI.getSetCCResultType(LHS.getValueType()), LHS,
|
|
|
|
Tmp2, DAG.getCondCode(TLI.getCmpLibcallCC(LC2)));
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::OR, dl, Tmp1.getValueType(), Tmp1, Tmp2);
|
2008-07-27 21:46:04 +00:00
|
|
|
Tmp2 = SDValue();
|
2006-12-15 02:59:56 +00:00
|
|
|
}
|
2008-07-07 07:18:09 +00:00
|
|
|
LHS = LegalizeOp(Tmp1);
|
2006-12-15 02:59:56 +00:00
|
|
|
RHS = Tmp2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LHSLo, LHSHi, RHSLo, RHSHi;
|
2006-02-01 07:19:44 +00:00
|
|
|
ExpandOp(LHS, LHSLo, LHSHi);
|
2007-10-06 01:24:11 +00:00
|
|
|
ExpandOp(RHS, RHSLo, RHSHi);
|
|
|
|
ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
|
|
|
|
|
|
|
|
if (VT==MVT::ppcf128) {
|
|
|
|
// FIXME: This generated code sucks. We want to generate
|
2008-09-12 00:30:56 +00:00
|
|
|
// FCMPU crN, hi1, hi2
|
2007-10-06 01:24:11 +00:00
|
|
|
// BNE crN, L:
|
2008-09-12 00:30:56 +00:00
|
|
|
// FCMPU crN, lo1, lo2
|
2007-10-06 01:24:11 +00:00
|
|
|
// The following can be improved, but not that much.
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSHi, RHSHi, ISD::SETOEQ);
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSLo.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSLo, RHSLo, CCCode);
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
|
|
|
|
Tmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSHi, RHSHi, ISD::SETUNE);
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSHi, RHSHi, CCCode);
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::AND, dl, Tmp1.getValueType(), Tmp1, Tmp2);
|
|
|
|
Tmp1 = DAG.getNode(ISD::OR, dl, Tmp1.getValueType(), Tmp1, Tmp3);
|
2008-07-27 21:46:04 +00:00
|
|
|
Tmp2 = SDValue();
|
2007-10-06 01:24:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (CCCode) {
|
2006-02-01 07:19:44 +00:00
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETNE:
|
|
|
|
if (RHSLo == RHSHi)
|
|
|
|
if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo))
|
|
|
|
if (RHSCST->isAllOnesValue()) {
|
|
|
|
// Comparison to -1.
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::AND, dl,LHSLo.getValueType(), LHSLo, LHSHi);
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp2 = RHSLo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::XOR, dl, LHSLo.getValueType(), LHSLo, RHSLo);
|
|
|
|
Tmp2 = DAG.getNode(ISD::XOR, dl, LHSLo.getValueType(), LHSHi, RHSHi);
|
|
|
|
Tmp1 = DAG.getNode(ISD::OR, dl, Tmp1.getValueType(), Tmp1, Tmp2);
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// If this is a comparison of the sign bit, just look at the top part.
|
|
|
|
// X > -1, x < 0
|
|
|
|
if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS))
|
2009-02-17 22:15:04 +00:00
|
|
|
if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT &&
|
2008-03-13 22:13:53 +00:00
|
|
|
CST->isNullValue()) || // X < 0
|
2006-02-01 07:19:44 +00:00
|
|
|
(cast<CondCodeSDNode>(CC)->get() == ISD::SETGT &&
|
|
|
|
CST->isAllOnesValue())) { // X > -1
|
|
|
|
Tmp1 = LHSHi;
|
|
|
|
Tmp2 = RHSHi;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This generated code sucks.
|
|
|
|
ISD::CondCode LowCC;
|
2007-02-08 22:16:19 +00:00
|
|
|
switch (CCCode) {
|
2006-02-01 07:19:44 +00:00
|
|
|
default: assert(0 && "Unknown integer setcc!");
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETULT: LowCC = ISD::SETULT; break;
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETUGT: LowCC = ISD::SETUGT; break;
|
|
|
|
case ISD::SETLE:
|
|
|
|
case ISD::SETULE: LowCC = ISD::SETULE; break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETUGE: LowCC = ISD::SETUGE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison
|
|
|
|
// Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands
|
|
|
|
// dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2;
|
|
|
|
|
|
|
|
// NOTE: on targets without efficient SELECT of bools, we can always use
|
|
|
|
// this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3)
|
2007-02-08 22:16:19 +00:00
|
|
|
TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL);
|
2009-01-01 15:52:00 +00:00
|
|
|
Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo.getValueType()),
|
2009-02-03 00:47:48 +00:00
|
|
|
LHSLo, RHSLo, LowCC, false, DagCombineInfo, dl);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (!Tmp1.getNode())
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(LHSLo.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSLo, RHSLo, LowCC);
|
|
|
|
Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-02-03 00:47:48 +00:00
|
|
|
LHSHi, RHSHi, CCCode, false, DagCombineInfo, dl);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (!Tmp2.getNode())
|
2009-02-02 20:41:04 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SETCC, dl,
|
2009-01-01 15:52:00 +00:00
|
|
|
TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-04-10 18:48:47 +00:00
|
|
|
LHSHi, RHSHi, CC);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.getNode());
|
|
|
|
ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.getNode());
|
2008-03-13 22:13:53 +00:00
|
|
|
if ((Tmp1C && Tmp1C->isNullValue()) ||
|
|
|
|
(Tmp2C && Tmp2C->isNullValue() &&
|
2007-02-08 22:16:19 +00:00
|
|
|
(CCCode == ISD::SETLE || CCCode == ISD::SETGE ||
|
|
|
|
CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) ||
|
2008-03-13 22:13:53 +00:00
|
|
|
(Tmp2C && Tmp2C->getAPIntValue() == 1 &&
|
2007-02-08 22:16:19 +00:00
|
|
|
(CCCode == ISD::SETLT || CCCode == ISD::SETGT ||
|
|
|
|
CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) {
|
|
|
|
// low part is known false, returns high part.
|
|
|
|
// For LE / GE, if high part is known false, ignore the low part.
|
|
|
|
// For LT / GT, if high part is known true, ignore the low part.
|
|
|
|
Tmp1 = Tmp2;
|
2008-07-27 21:46:04 +00:00
|
|
|
Tmp2 = SDValue();
|
2007-02-08 22:16:19 +00:00
|
|
|
} else {
|
2009-01-01 15:52:00 +00:00
|
|
|
Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi.getValueType()),
|
|
|
|
LHSHi, RHSHi, ISD::SETEQ, false,
|
2009-02-03 00:47:48 +00:00
|
|
|
DagCombineInfo, dl);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (!Result.getNode())
|
2009-02-02 20:41:04 +00:00
|
|
|
Result=DAG.getSetCC(dl, TLI.getSetCCResultType(LHSHi.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
LHSHi, RHSHi, ISD::SETEQ);
|
2009-02-02 20:41:04 +00:00
|
|
|
Result = LegalizeOp(DAG.getNode(ISD::SELECT, dl, Tmp1.getValueType(),
|
2007-02-08 22:16:19 +00:00
|
|
|
Result, Tmp1, Tmp2));
|
|
|
|
Tmp1 = Result;
|
2008-07-27 21:46:04 +00:00
|
|
|
Tmp2 = SDValue();
|
2007-02-08 22:16:19 +00:00
|
|
|
}
|
2006-02-01 07:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-15 02:59:56 +00:00
|
|
|
}
|
2006-02-01 07:19:44 +00:00
|
|
|
LHS = Tmp1;
|
|
|
|
RHS = Tmp2;
|
|
|
|
}
|
|
|
|
|
2008-10-15 02:05:31 +00:00
|
|
|
/// LegalizeSetCCCondCode - Legalize a SETCC with given LHS and RHS and
|
|
|
|
/// condition code CC on the current target. This routine assumes LHS and rHS
|
|
|
|
/// have already been legalized by LegalizeSetCCOperands. It expands SETCC with
|
|
|
|
/// illegal condition code into AND / OR of multiple SETCC values.
|
|
|
|
void SelectionDAGLegalize::LegalizeSetCCCondCode(MVT VT,
|
|
|
|
SDValue &LHS, SDValue &RHS,
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue &CC,
|
|
|
|
DebugLoc dl) {
|
2008-10-15 02:05:31 +00:00
|
|
|
MVT OpVT = LHS.getValueType();
|
|
|
|
ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
|
|
|
|
switch (TLI.getCondCodeAction(CCCode, OpVT)) {
|
|
|
|
default: assert(0 && "Unknown condition code action!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// Nothing to do.
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID;
|
|
|
|
unsigned Opc = 0;
|
|
|
|
switch (CCCode) {
|
|
|
|
default: assert(0 && "Don't know how to expand this condition!"); abort();
|
2008-10-21 03:12:54 +00:00
|
|
|
case ISD::SETOEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETOGT: CC1 = ISD::SETGT; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETOGE: CC1 = ISD::SETGE; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETOLT: CC1 = ISD::SETLT; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETOLE: CC1 = ISD::SETLE; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETONE: CC1 = ISD::SETNE; CC2 = ISD::SETO; Opc = ISD::AND; break;
|
|
|
|
case ISD::SETUEQ: CC1 = ISD::SETEQ; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
|
|
|
case ISD::SETUGT: CC1 = ISD::SETGT; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
|
|
|
case ISD::SETUGE: CC1 = ISD::SETGE; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
|
|
|
case ISD::SETULT: CC1 = ISD::SETLT; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
|
|
|
case ISD::SETULE: CC1 = ISD::SETLE; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
|
|
|
case ISD::SETUNE: CC1 = ISD::SETNE; CC2 = ISD::SETUO; Opc = ISD::OR; break;
|
2008-10-15 02:05:31 +00:00
|
|
|
// FIXME: Implement more expansions.
|
|
|
|
}
|
|
|
|
|
2009-02-02 20:41:04 +00:00
|
|
|
SDValue SetCC1 = DAG.getSetCC(dl, VT, LHS, RHS, CC1);
|
|
|
|
SDValue SetCC2 = DAG.getSetCC(dl, VT, LHS, RHS, CC2);
|
|
|
|
LHS = DAG.getNode(Opc, dl, VT, SetCC1, SetCC2);
|
2008-10-15 02:05:31 +00:00
|
|
|
RHS = SDValue();
|
|
|
|
CC = SDValue();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
/// EmitStackConvert - Emit a store/load combination to the stack. This stores
|
|
|
|
/// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does
|
|
|
|
/// a load from the stack slot to DestVT, extending it if needed.
|
|
|
|
/// The resultant code need not be legal.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::EmitStackConvert(SDValue SrcOp,
|
|
|
|
MVT SlotVT,
|
2009-02-02 22:12:50 +00:00
|
|
|
MVT DestVT,
|
|
|
|
DebugLoc dl) {
|
2005-12-23 00:16:34 +00:00
|
|
|
// Create the stack frame object.
|
2009-04-10 18:48:47 +00:00
|
|
|
unsigned SrcAlign =
|
|
|
|
TLI.getTargetData()->getPrefTypeAlignment(SrcOp.getValueType().
|
|
|
|
getTypeForMVT());
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-02-11 18:58:42 +00:00
|
|
|
FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr);
|
2008-02-06 22:27:42 +00:00
|
|
|
int SPFI = StackPtrFI->getIndex();
|
2009-01-29 21:02:43 +00:00
|
|
|
const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned SrcSize = SrcOp.getValueType().getSizeInBits();
|
|
|
|
unsigned SlotSize = SlotVT.getSizeInBits();
|
|
|
|
unsigned DestSize = DestVT.getSizeInBits();
|
2009-04-10 18:48:47 +00:00
|
|
|
unsigned DestAlign =
|
|
|
|
TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForMVT());
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
// Emit a store to the stack slot. Use a truncstore if the input value is
|
|
|
|
// later than DestVT.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Store;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
if (SrcSize > SlotSize)
|
2009-02-02 22:12:50 +00:00
|
|
|
Store = DAG.getTruncStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
|
2009-01-29 21:02:43 +00:00
|
|
|
SV, 0, SlotVT, false, SrcAlign);
|
2008-01-16 07:45:30 +00:00
|
|
|
else {
|
|
|
|
assert(SrcSize == SlotSize && "Invalid store");
|
2009-02-02 22:12:50 +00:00
|
|
|
Store = DAG.getStore(DAG.getEntryNode(), dl, SrcOp, FIPtr,
|
2009-01-29 21:02:43 +00:00
|
|
|
SV, 0, false, SrcAlign);
|
2008-01-16 07:45:30 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-23 00:16:34 +00:00
|
|
|
// Result is a load from the stack slot.
|
2008-01-16 07:45:30 +00:00
|
|
|
if (SlotSize == DestSize)
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getLoad(DestVT, dl, Store, FIPtr, SV, 0, false, DestAlign);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
assert(SlotSize < DestSize && "Unknown extension!");
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getExtLoad(ISD::EXTLOAD, dl, DestVT, Store, FIPtr, SV, 0, SlotVT,
|
2008-07-05 20:40:31 +00:00
|
|
|
false, DestAlign);
|
2005-12-23 00:16:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) {
|
2009-02-02 22:12:50 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2006-04-04 17:23:26 +00:00
|
|
|
// Create a vector sized/aligned stack slot, store the value to element #0,
|
|
|
|
// then load the whole vector back out.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StackPtr = DAG.CreateStackTemporary(Node->getValueType(0));
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-02-11 18:58:42 +00:00
|
|
|
FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr);
|
2008-02-06 22:27:42 +00:00
|
|
|
int SPFI = StackPtrFI->getIndex();
|
|
|
|
|
2009-04-18 20:16:54 +00:00
|
|
|
SDValue Ch = DAG.getTruncStore(DAG.getEntryNode(), dl, Node->getOperand(0),
|
|
|
|
StackPtr,
|
|
|
|
PseudoSourceValue::getFixedStack(SPFI), 0,
|
|
|
|
Node->getValueType(0).getVectorElementType());
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getLoad(Node->getValueType(0), dl, Ch, StackPtr,
|
2008-07-11 22:44:52 +00:00
|
|
|
PseudoSourceValue::getFixedStack(SPFI), 0);
|
2006-04-04 17:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
/// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't
|
2007-07-16 14:29:03 +00:00
|
|
|
/// support the operation, but do support the resultant vector type.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
|
2009-04-13 20:20:30 +00:00
|
|
|
unsigned NumElems = Node->getNumOperands();
|
|
|
|
SDValue SplatValue = Node->getOperand(0);
|
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
|
|
|
MVT VT = Node->getValueType(0);
|
|
|
|
MVT OpVT = SplatValue.getValueType();
|
|
|
|
MVT EltVT = VT.getVectorElementType();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// If the only non-undef value is the low element, turn this into a
|
2006-03-20 01:52:29 +00:00
|
|
|
// SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X.
|
2006-03-19 06:31:19 +00:00
|
|
|
bool isOnlyLowElement = true;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
// FIXME: it would be far nicer to change this into map<SDValue,uint64_t>
|
2008-03-09 00:29:42 +00:00
|
|
|
// and use a bitmask instead of a list of elements.
|
2009-04-27 18:41:29 +00:00
|
|
|
// FIXME: this doesn't treat <0, u, 0, u> for example, as a splat.
|
2008-07-27 21:46:04 +00:00
|
|
|
std::map<SDValue, std::vector<unsigned> > Values;
|
2006-03-24 01:17:21 +00:00
|
|
|
Values[SplatValue].push_back(0);
|
2006-03-24 07:29:17 +00:00
|
|
|
bool isConstant = true;
|
|
|
|
if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) &&
|
|
|
|
SplatValue.getOpcode() != ISD::UNDEF)
|
|
|
|
isConstant = false;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
for (unsigned i = 1; i < NumElems; ++i) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue V = Node->getOperand(i);
|
2006-04-19 23:17:50 +00:00
|
|
|
Values[V].push_back(i);
|
2006-03-24 01:17:21 +00:00
|
|
|
if (V.getOpcode() != ISD::UNDEF)
|
2006-03-19 06:31:19 +00:00
|
|
|
isOnlyLowElement = false;
|
2006-03-24 01:17:21 +00:00
|
|
|
if (SplatValue != V)
|
2009-04-10 18:48:47 +00:00
|
|
|
SplatValue = SDValue(0, 0);
|
2006-03-24 07:29:17 +00:00
|
|
|
|
|
|
|
// If this isn't a constant element or an undef, we can't use a constant
|
|
|
|
// pool load.
|
|
|
|
if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) &&
|
|
|
|
V.getOpcode() != ISD::UNDEF)
|
|
|
|
isConstant = false;
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
if (isOnlyLowElement) {
|
|
|
|
// If the low element is an undef too, then this whole things is an undef.
|
|
|
|
if (Node->getOperand(0).getOpcode() == ISD::UNDEF)
|
2009-04-13 20:20:30 +00:00
|
|
|
return DAG.getUNDEF(VT);
|
2006-03-19 06:31:19 +00:00
|
|
|
// Otherwise, turn this into a scalar_to_vector node.
|
2009-04-13 20:20:30 +00:00
|
|
|
return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Node->getOperand(0));
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-24 07:29:17 +00:00
|
|
|
// If all elements are constants, create a load from the constant pool.
|
2006-03-19 06:31:19 +00:00
|
|
|
if (isConstant) {
|
|
|
|
std::vector<Constant*> CV;
|
2006-03-24 01:17:21 +00:00
|
|
|
for (unsigned i = 0, e = NumElems; i != e; ++i) {
|
2009-02-17 22:15:04 +00:00
|
|
|
if (ConstantFPSDNode *V =
|
2006-03-19 06:31:19 +00:00
|
|
|
dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) {
|
2008-09-12 18:08:03 +00:00
|
|
|
CV.push_back(const_cast<ConstantFP *>(V->getConstantFPValue()));
|
2009-02-17 22:15:04 +00:00
|
|
|
} else if (ConstantSDNode *V =
|
2009-04-10 18:48:47 +00:00
|
|
|
dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
|
2008-09-12 18:08:03 +00:00
|
|
|
CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue()));
|
2006-03-19 06:31:19 +00:00
|
|
|
} else {
|
|
|
|
assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
|
2009-04-13 20:20:30 +00:00
|
|
|
const Type *OpNTy = OpVT.getTypeForMVT();
|
2006-03-19 06:31:19 +00:00
|
|
|
CV.push_back(UndefValue::get(OpNTy));
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 02:26:10 +00:00
|
|
|
Constant *CP = ConstantVector::get(CV);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy());
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
|
2008-09-16 22:05:41 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
|
|
|
false, Alignment);
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (SplatValue.getNode()) { // Splat of one value?
|
2006-03-24 07:29:17 +00:00
|
|
|
// Build the shuffle constant vector: <0, 0, 0, 0>
|
2009-04-27 18:41:29 +00:00
|
|
|
SmallVector<int, 8> ZeroVec(NumElems, 0);
|
2006-03-24 01:17:21 +00:00
|
|
|
|
2006-03-24 07:29:17 +00:00
|
|
|
// If the target supports VECTOR_SHUFFLE and this shuffle mask, use it.
|
2009-04-27 18:41:29 +00:00
|
|
|
if (TLI.isShuffleMaskLegal(ZeroVec, Node->getValueType(0))) {
|
2006-03-24 07:29:17 +00:00
|
|
|
// Get the splatted value into the low element of a vector register.
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue LowValVec =
|
2009-04-13 20:20:30 +00:00
|
|
|
DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, SplatValue);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-24 07:29:17 +00:00
|
|
|
// Return shuffle(LowValVec, undef, <0,0,0,0>)
|
2009-04-27 18:41:29 +00:00
|
|
|
return DAG.getVectorShuffle(VT, dl, LowValVec, DAG.getUNDEF(VT),
|
|
|
|
&ZeroVec[0]);
|
2006-03-24 07:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
// If there are only two unique elements, we may be able to turn this into a
|
|
|
|
// vector shuffle.
|
|
|
|
if (Values.size() == 2) {
|
2008-03-09 00:29:42 +00:00
|
|
|
// Get the two values in deterministic order.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Val1 = Node->getOperand(1);
|
|
|
|
SDValue Val2;
|
|
|
|
std::map<SDValue, std::vector<unsigned> >::iterator MI = Values.begin();
|
2008-03-09 00:29:42 +00:00
|
|
|
if (MI->first != Val1)
|
|
|
|
Val2 = MI->first;
|
|
|
|
else
|
|
|
|
Val2 = (++MI)->first;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-04-10 18:48:47 +00:00
|
|
|
// If Val1 is an undef, make sure it ends up as Val2, to ensure that our
|
2008-03-09 00:29:42 +00:00
|
|
|
// vector shuffle has the undef vector on the RHS.
|
|
|
|
if (Val1.getOpcode() == ISD::UNDEF)
|
|
|
|
std::swap(Val1, Val2);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
// Build the shuffle constant vector: e.g. <0, 4, 0, 4>
|
2009-04-27 18:41:29 +00:00
|
|
|
SmallVector<int, 8> ShuffleMask(NumElems, -1);
|
2008-03-09 00:29:42 +00:00
|
|
|
|
|
|
|
// Set elements of the shuffle mask for Val1.
|
|
|
|
std::vector<unsigned> &Val1Elts = Values[Val1];
|
|
|
|
for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i)
|
2009-04-27 18:41:29 +00:00
|
|
|
ShuffleMask[Val1Elts[i]] = 0;
|
2008-03-09 00:29:42 +00:00
|
|
|
|
|
|
|
// Set elements of the shuffle mask for Val2.
|
|
|
|
std::vector<unsigned> &Val2Elts = Values[Val2];
|
|
|
|
for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i)
|
|
|
|
if (Val2.getOpcode() != ISD::UNDEF)
|
2009-04-27 18:41:29 +00:00
|
|
|
ShuffleMask[Val2Elts[i]] = NumElems;
|
2006-03-24 01:17:21 +00:00
|
|
|
|
2008-03-09 00:29:42 +00:00
|
|
|
// If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it.
|
2009-04-13 20:20:30 +00:00
|
|
|
if (TLI.isOperationLegalOrCustom(ISD::SCALAR_TO_VECTOR, VT) &&
|
2009-04-27 18:41:29 +00:00
|
|
|
TLI.isShuffleMaskLegal(ShuffleMask, VT)) {
|
2009-04-13 20:20:30 +00:00
|
|
|
Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Val1);
|
|
|
|
Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Val2);
|
2009-04-27 18:41:29 +00:00
|
|
|
return DAG.getVectorShuffle(VT, dl, Val1, Val2, &ShuffleMask[0]);
|
2006-03-24 01:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
// Otherwise, we can't handle this case efficiently. Allocate a sufficiently
|
|
|
|
// aligned object on the stack, store each element into it, then load
|
|
|
|
// the result as a vector.
|
|
|
|
// Create the stack frame object.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue FIPtr = DAG.CreateStackTemporary(VT);
|
2009-01-29 21:02:43 +00:00
|
|
|
int FI = cast<FrameIndexSDNode>(FIPtr.getNode())->getIndex();
|
|
|
|
const Value *SV = PseudoSourceValue::getFixedStack(FI);
|
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
// Emit a store of each element to the stack slot.
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Stores;
|
2009-04-13 20:20:30 +00:00
|
|
|
unsigned TypeByteSize = OpVT.getSizeInBits() / 8;
|
2006-03-19 06:31:19 +00:00
|
|
|
// Store (in the right endianness) the elements to memory.
|
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
|
|
|
|
// Ignore undef elements.
|
|
|
|
if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-22 01:46:54 +00:00
|
|
|
unsigned Offset = TypeByteSize*i;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Idx = DAG.getConstant(Offset, FIPtr.getValueType());
|
2009-02-02 22:12:50 +00:00
|
|
|
Idx = DAG.getNode(ISD::ADD, dl, FIPtr.getValueType(), FIPtr, Idx);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Stores.push_back(DAG.getStore(DAG.getEntryNode(), dl, Node->getOperand(i),
|
|
|
|
Idx, SV, Offset));
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StoreChain;
|
2006-03-19 06:31:19 +00:00
|
|
|
if (!Stores.empty()) // Not all undef elements?
|
2009-02-02 22:12:50 +00:00
|
|
|
StoreChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2006-08-08 02:23:42 +00:00
|
|
|
&Stores[0], Stores.size());
|
2006-03-19 06:31:19 +00:00
|
|
|
else
|
|
|
|
StoreChain = DAG.getEntryNode();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
// Result is a load from the stack slot.
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getLoad(VT, dl, StoreChain, FIPtr, SV, 0);
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
|
|
|
|
2005-04-02 04:00:59 +00:00
|
|
|
void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op, SDValue Amt,
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue &Lo, SDValue &Hi,
|
|
|
|
DebugLoc dl) {
|
2005-04-02 04:00:59 +00:00
|
|
|
// Expand the subcomponents.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LHSL, LHSH;
|
2005-04-02 04:00:59 +00:00
|
|
|
ExpandOp(Op, LHSL, LHSH);
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[] = { LHSL, LHSH, Amt };
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = LHSL.getValueType();
|
2009-04-09 23:54:40 +00:00
|
|
|
Lo = DAG.getNode(NodeOp, dl, DAG.getVTList(VT, VT), Ops, 3);
|
2005-04-02 04:00:59 +00:00
|
|
|
Hi = Lo.getValue(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
/// ExpandShift - Try to find a clever way to expand this shift operation out to
|
|
|
|
/// smaller elements. If we can't find a way that is more efficient than a
|
|
|
|
/// libcall on this target, return false. Otherwise, return true with the
|
|
|
|
/// low-parts expanded into Lo and Hi.
|
2009-04-10 18:48:47 +00:00
|
|
|
bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDValue Op, SDValue Amt,
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue &Lo, SDValue &Hi,
|
|
|
|
DebugLoc dl) {
|
2005-01-19 04:19:40 +00:00
|
|
|
assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) &&
|
|
|
|
"This is not a shift!");
|
2005-04-06 21:13:14 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NVT = TLI.getTypeToTransformTo(Op.getValueType());
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShAmt = LegalizeOp(Amt);
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ShTy = ShAmt.getValueType();
|
|
|
|
unsigned ShBits = ShTy.getSizeInBits();
|
|
|
|
unsigned VTBits = Op.getValueType().getSizeInBits();
|
|
|
|
unsigned NVTBits = NVT.getSizeInBits();
|
2005-04-06 21:13:14 +00:00
|
|
|
|
2007-10-14 20:35:12 +00:00
|
|
|
// Handle the case when Amt is an immediate.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.getNode())) {
|
2008-09-12 16:56:44 +00:00
|
|
|
unsigned Cst = CN->getZExtValue();
|
2005-04-06 21:13:14 +00:00
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InL, InH;
|
2005-04-06 21:13:14 +00:00
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
|
|
|
if (Cst > VTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else if (Cst > NVTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SHL, dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
NVT, InL, DAG.getConstant(Cst-NVTBits, ShTy));
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = InL;
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SHL, dl, NVT, InL, DAG.getConstant(Cst, ShTy));
|
|
|
|
Hi = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SHL, dl, NVT, InH, DAG.getConstant(Cst, ShTy)),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL,
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getConstant(NVTBits-Cst, ShTy)));
|
2005-04-06 21:13:14 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
if (Cst > VTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else if (Cst > NVTBits) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Lo = DAG.getNode(ISD::SRL, dl, NVT,
|
2009-04-10 18:48:47 +00:00
|
|
|
InH, DAG.getConstant(Cst-NVTBits, ShTy));
|
2005-04-06 21:13:14 +00:00
|
|
|
Hi = DAG.getConstant(0, NVT);
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = InH;
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL, DAG.getConstant(Cst, ShTy)),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::SHL, dl, NVT, InH,
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getConstant(NVTBits-Cst, ShTy)));
|
|
|
|
Hi = DAG.getNode(ISD::SRL, dl, NVT, InH, DAG.getConstant(Cst, ShTy));
|
2005-04-06 21:13:14 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
|
|
|
if (Cst > VTBits) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = Lo = DAG.getNode(ISD::SRA, dl, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
|
|
|
} else if (Cst > NVTBits) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SRA, dl, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(Cst-NVTBits, ShTy));
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = InH;
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, InH,
|
2005-04-11 20:08:52 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL, DAG.getConstant(Cst, ShTy)),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getNode(ISD::SHL, dl,
|
2009-02-02 22:12:50 +00:00
|
|
|
NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy)));
|
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, InH, DAG.getConstant(Cst, ShTy));
|
2005-04-06 21:13:14 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Okay, the shift amount isn't constant. However, if we can tell that it is
|
|
|
|
// >= 32 or < 32, we can still simplify it, without knowing the actual value.
|
2008-02-20 16:57:27 +00:00
|
|
|
APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits));
|
|
|
|
APInt KnownZero, KnownOne;
|
2007-06-22 14:59:07 +00:00
|
|
|
DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-02-22 01:12:31 +00:00
|
|
|
// If we know that if any of the high bits of the shift amount are one, then
|
|
|
|
// we can do this as a couple of simple shifts.
|
2008-02-20 16:57:27 +00:00
|
|
|
if (KnownOne.intersects(Mask)) {
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Mask out the high bit, which we know is set.
|
2009-02-02 22:12:50 +00:00
|
|
|
Amt = DAG.getNode(ISD::AND, dl, Amt.getValueType(), Amt,
|
2008-02-20 16:57:27 +00:00
|
|
|
DAG.getConstant(~Mask, Amt.getValueType()));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InL, InH;
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
|
|
|
Lo = DAG.getConstant(0, NVT); // Low part is zero.
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SHL, dl, NVT, InL, Amt); // High part from Lo part.
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
Hi = DAG.getConstant(0, NVT); // Hi part is zero.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SRL, dl, NVT, InH, Amt); // Lo part from Hi part.
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, InH, // Sign extend high part.
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
DAG.getConstant(NVTBits-1, Amt.getValueType()));
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SRA, dl, NVT, InH, Amt); // Lo part from Hi part.
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-02-22 01:12:31 +00:00
|
|
|
// If we know that the high bits of the shift amount are all zero, then we can
|
|
|
|
// do this as a couple of simple shifts.
|
|
|
|
if ((KnownZero & Mask) == Mask) {
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Compute 32-amt.
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Amt2 = DAG.getNode(ISD::SUB, dl, Amt.getValueType(),
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
DAG.getConstant(NVTBits, Amt.getValueType()),
|
|
|
|
Amt);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InL, InH;
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SHL, dl, NVT, InL, Amt);
|
|
|
|
Hi = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SHL, dl, NVT, InH, Amt),
|
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL, Amt2));
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRL, dl, NVT, InH, Amt);
|
|
|
|
Lo = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL, Amt),
|
|
|
|
DAG.getNode(ISD::SHL, dl, NVT, InH, Amt2));
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, InH, Amt);
|
|
|
|
Lo = DAG.getNode(ISD::OR, dl, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, dl, NVT, InL, Amt),
|
|
|
|
DAG.getNode(ISD::SHL, dl, NVT, InH, Amt2));
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-04-06 21:13:14 +00:00
|
|
|
return false;
|
2005-01-19 04:19:40 +00:00
|
|
|
}
|
2005-01-21 06:05:23 +00:00
|
|
|
|
2005-01-23 04:42:50 +00:00
|
|
|
|
2005-01-21 06:05:23 +00:00
|
|
|
// ExpandLibCall - Expand a node into a call to a libcall. If the result value
|
|
|
|
// does not fit into a register, return the lo part and set the hi part to the
|
|
|
|
// by-reg argument. If it does fit into a single register, return the result
|
|
|
|
// and leave the Hi part unset.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node,
|
|
|
|
bool isSigned, SDValue &Hi) {
|
2006-02-13 09:18:02 +00:00
|
|
|
assert(!IsLegalizingCall && "Cannot overlap legalization of calls!");
|
2009-02-17 22:15:04 +00:00
|
|
|
// The input chain to this libcall is the entry node of the function.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Legalizing the call will automatically add the previous call to the
|
|
|
|
// dependence.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InChain = DAG.getEntryNode();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-21 06:05:23 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
2006-12-31 05:55:36 +00:00
|
|
|
TargetLowering::ArgListEntry Entry;
|
2005-01-21 06:05:23 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ArgVT = Node->getOperand(i).getValueType();
|
|
|
|
const Type *ArgTy = ArgVT.getTypeForMVT();
|
2009-02-17 22:15:04 +00:00
|
|
|
Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
|
2007-03-07 16:25:09 +00:00
|
|
|
Entry.isSExt = isSigned;
|
2008-02-14 17:28:50 +00:00
|
|
|
Entry.isZExt = !isSigned;
|
2006-12-31 05:55:36 +00:00
|
|
|
Args.push_back(Entry);
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2008-09-16 21:48:12 +00:00
|
|
|
SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
|
2008-10-30 08:01:45 +00:00
|
|
|
TLI.getPointerTy());
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-05-11 19:02:11 +00:00
|
|
|
// Splice the libcall in wherever FindInputOutputChains tells us to.
|
2008-06-06 12:08:01 +00:00
|
|
|
const Type *RetTy = Node->getValueType(0).getTypeForMVT();
|
2009-04-10 18:48:47 +00:00
|
|
|
std::pair<SDValue, SDValue> CallInfo =
|
2008-09-26 19:31:26 +00:00
|
|
|
TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false,
|
2009-01-30 23:10:59 +00:00
|
|
|
CallingConv::C, false, Callee, Args, DAG,
|
|
|
|
Node->getDebugLoc());
|
2005-05-11 19:02:11 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Legalize the call sequence, starting with the chain. This will advance
|
|
|
|
// the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that
|
|
|
|
// was added by LowerCallTo (guaranteeing proper serialization of calls).
|
|
|
|
LegalizeOp(CallInfo.second);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Result;
|
2005-05-11 19:02:11 +00:00
|
|
|
switch (getTypeAction(CallInfo.first.getValueType())) {
|
2005-01-21 06:05:23 +00:00
|
|
|
default: assert(0 && "Unknown thing");
|
|
|
|
case Legal:
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = CallInfo.first;
|
2005-09-02 20:26:58 +00:00
|
|
|
break;
|
2005-01-21 06:05:23 +00:00
|
|
|
case Expand:
|
2005-09-02 20:26:58 +00:00
|
|
|
ExpandOp(CallInfo.first, Result, Hi);
|
|
|
|
break;
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2008-08-14 20:04:46 +00:00
|
|
|
/// LegalizeINT_TO_FP - Legalize a [US]INT_TO_FP operation.
|
|
|
|
///
|
|
|
|
SDValue SelectionDAGLegalize::
|
2009-02-02 19:03:57 +00:00
|
|
|
LegalizeINT_TO_FP(SDValue Result, bool isSigned, MVT DestTy, SDValue Op,
|
|
|
|
DebugLoc dl) {
|
2008-08-14 20:04:46 +00:00
|
|
|
bool isCustom = false;
|
|
|
|
SDValue Tmp1;
|
|
|
|
switch (getTypeAction(Op.getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
switch (TLI.getOperationAction(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP,
|
|
|
|
Op.getValueType())) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Op);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode())
|
2008-08-14 20:04:46 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
else
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, dl,
|
2008-08-14 20:04:46 +00:00
|
|
|
DestTy, Tmp1);
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp1.getNode()) Result = Tmp1;
|
2008-08-14 20:04:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = ExpandLegalINT_TO_FP(isSigned, LegalizeOp(Op), DestTy, dl);
|
2008-08-14 20:04:46 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = PromoteLegalINT_TO_FP(LegalizeOp(Op), DestTy, isSigned, dl);
|
2008-08-14 20:04:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Expand:
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = ExpandIntToFP(isSigned, DestTy, Op, dl) ;
|
2008-08-14 20:04:46 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(Op);
|
|
|
|
if (isSigned) {
|
2009-02-02 19:03:57 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Tmp1.getValueType(),
|
2009-04-10 18:48:47 +00:00
|
|
|
Tmp1, DAG.getValueType(Op.getValueType()));
|
2008-08-14 20:04:46 +00:00
|
|
|
} else {
|
2009-04-10 18:48:47 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, dl, Op.getValueType());
|
2008-08-14 20:04:46 +00:00
|
|
|
}
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode())
|
2008-08-14 20:04:46 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
else
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP, dl,
|
2008-08-14 20:04:46 +00:00
|
|
|
DestTy, Tmp1);
|
|
|
|
Result = LegalizeOp(Result); // The 'op' is not necessarily legal!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2007-04-27 07:33:31 +00:00
|
|
|
/// ExpandIntToFP - Expand a [US]INT_TO_FP operation.
|
|
|
|
///
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::
|
2009-02-02 19:03:57 +00:00
|
|
|
ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source, DebugLoc dl) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT SourceVT = Source.getValueType();
|
2008-03-11 01:59:03 +00:00
|
|
|
bool ExpandSource = getTypeAction(SourceVT) == Expand;
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-08-14 20:04:46 +00:00
|
|
|
// Expand unsupported int-to-fp vector casts by unrolling them.
|
|
|
|
if (DestTy.isVector()) {
|
|
|
|
if (!ExpandSource)
|
|
|
|
return LegalizeOp(UnrollVectorOp(Source));
|
|
|
|
MVT DestEltTy = DestTy.getVectorElementType();
|
|
|
|
if (DestTy.getVectorNumElements() == 1) {
|
|
|
|
SDValue Scalar = ScalarizeVectorOp(Source);
|
|
|
|
SDValue Result = LegalizeINT_TO_FP(SDValue(), isSigned,
|
2009-02-02 19:03:57 +00:00
|
|
|
DestEltTy, Scalar, dl);
|
2009-02-25 22:49:59 +00:00
|
|
|
return DAG.getNode(ISD::BUILD_VECTOR, dl, DestTy, Result);
|
2008-08-14 20:04:46 +00:00
|
|
|
}
|
|
|
|
SDValue Lo, Hi;
|
|
|
|
SplitVectorOp(Source, Lo, Hi);
|
|
|
|
MVT SplitDestTy = MVT::getVectorVT(DestEltTy,
|
|
|
|
DestTy.getVectorNumElements() / 2);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue LoResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy,
|
2009-02-02 19:03:57 +00:00
|
|
|
Lo, dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue HiResult = LegalizeINT_TO_FP(SDValue(), isSigned, SplitDestTy,
|
2009-02-02 19:03:57 +00:00
|
|
|
Hi, dl);
|
|
|
|
return LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, dl, DestTy, LoResult,
|
2008-10-13 18:46:18 +00:00
|
|
|
HiResult));
|
2008-08-14 20:04:46 +00:00
|
|
|
}
|
|
|
|
|
2008-04-01 02:18:22 +00:00
|
|
|
// Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc.
|
|
|
|
if (!isSigned && SourceVT != MVT::i32) {
|
2008-03-05 02:07:31 +00:00
|
|
|
// The integer value loaded will be incorrectly if the 'sign bit' of the
|
2006-01-28 08:25:58 +00:00
|
|
|
// incoming integer is set. To handle this, we dynamically test to see if
|
|
|
|
// it is set, and, if so, add a fudge factor.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Hi;
|
2008-03-11 01:59:03 +00:00
|
|
|
if (ExpandSource) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Lo;
|
2008-03-11 01:59:03 +00:00
|
|
|
ExpandOp(Source, Lo, Hi);
|
2009-02-02 19:03:57 +00:00
|
|
|
Source = DAG.getNode(ISD::BUILD_PAIR, dl, SourceVT, Lo, Hi);
|
2008-03-11 01:59:03 +00:00
|
|
|
} else {
|
|
|
|
// The comparison for the sign bit will use the entire operand.
|
|
|
|
Hi = Source;
|
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-11-04 20:52:49 +00:00
|
|
|
// Check to see if the target has a custom way to lower this. If so, use
|
|
|
|
// it. (Note we've already expanded the operand in this case.)
|
2008-10-21 20:50:01 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::UINT_TO_FP, SourceVT)) {
|
|
|
|
default: assert(0 && "This action not implemented for this operation!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
break; // This case is handled below.
|
|
|
|
case TargetLowering::Custom: {
|
2009-02-07 00:55:49 +00:00
|
|
|
SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::UINT_TO_FP, dl, DestTy,
|
2009-04-10 18:48:47 +00:00
|
|
|
Source), DAG);
|
2008-10-21 20:50:01 +00:00
|
|
|
if (NV.getNode())
|
|
|
|
return LegalizeOp(NV);
|
|
|
|
break; // The target decided this was legal after all
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// If this is unsigned, and not supported, first perform the conversion to
|
|
|
|
// signed, then adjust the result if the sign bit is set.
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue SignedConv = ExpandIntToFP(true, DestTy, Source, dl);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue SignSet = DAG.getSetCC(dl,
|
2009-02-02 19:03:57 +00:00
|
|
|
TLI.getSetCCResultType(Hi.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
Hi, DAG.getConstant(0, Hi.getValueType()),
|
|
|
|
ISD::SETLT);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue CstOffset = DAG.getNode(ISD::SELECT, dl, Zero.getValueType(),
|
2006-01-28 08:25:58 +00:00
|
|
|
SignSet, Four, Zero);
|
|
|
|
uint64_t FF = 0x5f800000ULL;
|
|
|
|
if (TLI.isLittleEndian()) FF <<= 32;
|
2009-03-08 01:47:41 +00:00
|
|
|
Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
2009-02-02 19:03:57 +00:00
|
|
|
CPIdx = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), CPIdx, CstOffset);
|
2008-09-22 22:40:08 +00:00
|
|
|
Alignment = std::min(Alignment, 4u);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue FudgeInReg;
|
2006-01-28 08:25:58 +00:00
|
|
|
if (DestTy == MVT::f32)
|
2009-02-02 19:03:57 +00:00
|
|
|
FudgeInReg = DAG.getLoad(MVT::f32, dl, DAG.getEntryNode(), CPIdx,
|
2008-09-16 22:05:41 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
|
|
|
false, Alignment);
|
2008-06-08 20:54:56 +00:00
|
|
|
else if (DestTy.bitsGT(MVT::f32))
|
2007-04-27 07:33:31 +00:00
|
|
|
// FIXME: Avoid the extend by construction the right constantpool?
|
2009-02-02 19:03:57 +00:00
|
|
|
FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, dl, DestTy, DAG.getEntryNode(),
|
2008-02-06 22:27:42 +00:00
|
|
|
CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
2008-09-16 22:05:41 +00:00
|
|
|
MVT::f32, false, Alignment);
|
2009-02-17 22:15:04 +00:00
|
|
|
else
|
2007-09-14 22:26:36 +00:00
|
|
|
assert(0 && "Unexpected conversion");
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT SCVT = SignedConv.getValueType();
|
2007-04-27 07:33:31 +00:00
|
|
|
if (SCVT != DestTy) {
|
|
|
|
// Destination type needs to be expanded as well. The FADD now we are
|
|
|
|
// constructing will be expanded into a libcall.
|
2008-06-06 12:08:01 +00:00
|
|
|
if (SCVT.getSizeInBits() != DestTy.getSizeInBits()) {
|
|
|
|
assert(SCVT.getSizeInBits() * 2 == DestTy.getSizeInBits());
|
2009-02-02 19:03:57 +00:00
|
|
|
SignedConv = DAG.getNode(ISD::BUILD_PAIR, dl, DestTy,
|
2007-04-27 07:33:31 +00:00
|
|
|
SignedConv, SignedConv.getValue(1));
|
|
|
|
}
|
2009-02-02 19:03:57 +00:00
|
|
|
SignedConv = DAG.getNode(ISD::BIT_CONVERT, dl, DestTy, SignedConv);
|
2007-04-27 07:33:31 +00:00
|
|
|
}
|
2009-02-02 19:03:57 +00:00
|
|
|
return DAG.getNode(ISD::FADD, dl, DestTy, SignedConv, FudgeInReg);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the target has a custom way to lower this. If so, use it.
|
2008-03-05 01:08:17 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) {
|
2006-01-28 08:25:58 +00:00
|
|
|
default: assert(0 && "This action not implemented for this operation!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
break; // This case is handled below.
|
|
|
|
case TargetLowering::Custom: {
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, dl, DestTy,
|
2009-04-10 18:48:47 +00:00
|
|
|
Source), DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (NV.getNode())
|
2006-01-28 08:25:58 +00:00
|
|
|
return LegalizeOp(NV);
|
|
|
|
break; // The target decided this was legal after all
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the source, then glue it back together for the call. We must expand
|
|
|
|
// the source in case it is shared (this pass of legalize must traverse it).
|
2008-03-11 01:59:03 +00:00
|
|
|
if (ExpandSource) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SrcLo, SrcHi;
|
2008-03-11 01:59:03 +00:00
|
|
|
ExpandOp(Source, SrcLo, SrcHi);
|
2009-02-02 19:03:57 +00:00
|
|
|
Source = DAG.getNode(ISD::BUILD_PAIR, dl, SourceVT, SrcLo, SrcHi);
|
2008-03-11 01:59:03 +00:00
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-07-17 02:36:29 +00:00
|
|
|
RTLIB::Libcall LC = isSigned ?
|
|
|
|
RTLIB::getSINTTOFP(SourceVT, DestTy) :
|
|
|
|
RTLIB::getUINTTOFP(SourceVT, DestTy);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unknown int value type");
|
|
|
|
|
2009-02-02 19:03:57 +00:00
|
|
|
Source = DAG.getNode(ISD::SINT_TO_FP, dl, DestTy, Source);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue HiPart;
|
2008-08-28 21:40:38 +00:00
|
|
|
SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart);
|
|
|
|
if (Result.getValueType() != DestTy && HiPart.getNode())
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_PAIR, dl, DestTy, Result, HiPart);
|
2008-03-10 23:03:31 +00:00
|
|
|
return Result;
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ExpandLegalINT_TO_FP - This function is responsible for legalizing a
|
|
|
|
/// INT_TO_FP operation of the specified operand when the target requests that
|
|
|
|
/// we expand it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
|
|
|
|
SDValue Op0,
|
2009-02-02 19:03:57 +00:00
|
|
|
MVT DestVT,
|
|
|
|
DebugLoc dl) {
|
2006-01-28 08:25:58 +00:00
|
|
|
if (Op0.getValueType() == MVT::i32) {
|
|
|
|
// simple 32-bit [signed|unsigned] integer to float/double expansion
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-01-16 07:03:22 +00:00
|
|
|
// Get the stack frame index of a 8 byte buffer.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StackSlot = DAG.CreateStackTemporary(MVT::f64);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// word offset constant for Hi/Lo address computation
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy());
|
2006-01-28 08:25:58 +00:00
|
|
|
// set up Hi and Lo (into buffer) address based on endian
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Hi = StackSlot;
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue Lo = DAG.getNode(ISD::ADD, dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
TLI.getPointerTy(), StackSlot, WordOff);
|
2006-03-23 05:29:04 +00:00
|
|
|
if (TLI.isLittleEndian())
|
|
|
|
std::swap(Hi, Lo);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// if signed map to unsigned space
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op0Mapped;
|
2006-01-28 08:25:58 +00:00
|
|
|
if (isSigned) {
|
|
|
|
// constant used to invert sign bit (signed to unsigned mapping)
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SignBit = DAG.getConstant(0x80000000u, MVT::i32);
|
2009-02-02 19:03:57 +00:00
|
|
|
Op0Mapped = DAG.getNode(ISD::XOR, dl, MVT::i32, Op0, SignBit);
|
2006-01-28 08:25:58 +00:00
|
|
|
} else {
|
|
|
|
Op0Mapped = Op0;
|
|
|
|
}
|
|
|
|
// store the lo of the constructed double - based on integer input
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Store1 = DAG.getStore(DAG.getEntryNode(), dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
Op0Mapped, Lo, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// initial hi portion of constructed double
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InitialHi = DAG.getConstant(0x43300000u, MVT::i32);
|
2006-01-28 08:25:58 +00:00
|
|
|
// store the hi of the constructed double - biased exponent
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Store2=DAG.getStore(Store1, dl, InitialHi, Hi, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// load the constructed double
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Load = DAG.getLoad(MVT::f64, dl, Store2, StackSlot, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// FP constant to bias correct the final result
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Bias = DAG.getConstantFP(isSigned ?
|
2009-04-10 18:48:47 +00:00
|
|
|
BitsToDouble(0x4330000080000000ULL) :
|
|
|
|
BitsToDouble(0x4330000000000000ULL),
|
2006-01-28 08:25:58 +00:00
|
|
|
MVT::f64);
|
|
|
|
// subtract the bias
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Sub = DAG.getNode(ISD::FSUB, dl, MVT::f64, Load, Bias);
|
2006-01-28 08:25:58 +00:00
|
|
|
// final result
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Result;
|
2006-01-28 08:25:58 +00:00
|
|
|
// handle final rounding
|
|
|
|
if (DestVT == MVT::f64) {
|
|
|
|
// do nothing
|
|
|
|
Result = Sub;
|
2008-06-08 20:54:56 +00:00
|
|
|
} else if (DestVT.bitsLT(MVT::f64)) {
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, dl, DestVT, Sub,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(0));
|
2008-06-08 20:54:56 +00:00
|
|
|
} else if (DestVT.bitsGT(MVT::f64)) {
|
2009-02-02 19:03:57 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, dl, DestVT, Sub);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet");
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Tmp1 = DAG.getNode(ISD::SINT_TO_FP, dl, DestVT, Op0);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue SignSet = DAG.getSetCC(dl, TLI.getSetCCResultType(Op0.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
Op0, DAG.getConstant(0, Op0.getValueType()),
|
|
|
|
ISD::SETLT);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue CstOffset = DAG.getNode(ISD::SELECT, dl, Zero.getValueType(),
|
2006-01-28 08:25:58 +00:00
|
|
|
SignSet, Four, Zero);
|
|
|
|
|
|
|
|
// If the sign bit of the integer is set, the large number will be treated
|
|
|
|
// as a negative number. To counteract this, the dynamic code adds an
|
|
|
|
// offset depending on the data type.
|
|
|
|
uint64_t FF;
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (Op0.getValueType().getSimpleVT()) {
|
2006-01-28 08:25:58 +00:00
|
|
|
default: assert(0 && "Unsupported integer type!");
|
|
|
|
case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float)
|
|
|
|
case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float)
|
|
|
|
case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float)
|
|
|
|
case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float)
|
|
|
|
}
|
|
|
|
if (TLI.isLittleEndian()) FF <<= 32;
|
2009-03-08 01:47:41 +00:00
|
|
|
Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
2009-02-02 19:03:57 +00:00
|
|
|
CPIdx = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), CPIdx, CstOffset);
|
2008-09-22 22:40:08 +00:00
|
|
|
Alignment = std::min(Alignment, 4u);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue FudgeInReg;
|
2006-01-28 08:25:58 +00:00
|
|
|
if (DestVT == MVT::f32)
|
2009-02-02 19:03:57 +00:00
|
|
|
FudgeInReg = DAG.getLoad(MVT::f32, dl, DAG.getEntryNode(), CPIdx,
|
2008-09-16 22:05:41 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
|
|
|
false, Alignment);
|
2006-01-28 08:25:58 +00:00
|
|
|
else {
|
2008-02-06 22:27:42 +00:00
|
|
|
FudgeInReg =
|
2009-02-02 19:03:57 +00:00
|
|
|
LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, dl, DestVT,
|
2008-02-06 22:27:42 +00:00
|
|
|
DAG.getEntryNode(), CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
2008-09-16 22:05:41 +00:00
|
|
|
MVT::f32, false, Alignment));
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
2009-02-02 19:03:57 +00:00
|
|
|
return DAG.getNode(ISD::FADD, dl, DestVT, Tmp1, FudgeInReg);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// PromoteLegalINT_TO_FP - This function is responsible for legalizing a
|
|
|
|
/// *INT_TO_FP operation of the specified operand when the target requests that
|
|
|
|
/// we promote it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP
|
|
|
|
/// operation that takes a larger input.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDValue LegalOp,
|
|
|
|
MVT DestVT,
|
2009-02-02 19:03:57 +00:00
|
|
|
bool isSigned,
|
|
|
|
DebugLoc dl) {
|
2006-01-28 08:25:58 +00:00
|
|
|
// First step, figure out the appropriate *INT_TO_FP operation to use.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewInTy = LegalOp.getValueType();
|
2006-01-28 08:25:58 +00:00
|
|
|
|
|
|
|
unsigned OpToUse = 0;
|
|
|
|
|
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
2008-06-06 12:08:01 +00:00
|
|
|
NewInTy = (MVT::SimpleValueType)(NewInTy.getSimpleVT()+1);
|
|
|
|
assert(NewInTy.isInteger() && "Ran out of possibilities!");
|
2006-01-28 08:25:58 +00:00
|
|
|
|
|
|
|
// If the target supports SINT_TO_FP of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewInTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::SINT_TO_FP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
|
|
|
if (isSigned) continue;
|
|
|
|
|
|
|
|
// If the target supports UINT_TO_FP of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewInTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::UINT_TO_FP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
|
|
|
|
|
|
|
// Otherwise, try a larger type.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, we found the operation and type to use. Zero extend our input to the
|
|
|
|
// desired type then run the operation on it.
|
2009-02-02 19:03:57 +00:00
|
|
|
return DAG.getNode(OpToUse, dl, DestVT,
|
2006-01-28 08:25:58 +00:00
|
|
|
DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND,
|
2009-02-02 19:03:57 +00:00
|
|
|
dl, NewInTy, LegalOp));
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// PromoteLegalFP_TO_INT - This function is responsible for legalizing a
|
|
|
|
/// FP_TO_*INT operation of the specified operand when the target requests that
|
|
|
|
/// we promote it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT
|
|
|
|
/// operation that returns a larger result.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDValue LegalOp,
|
|
|
|
MVT DestVT,
|
2009-02-02 19:03:57 +00:00
|
|
|
bool isSigned,
|
|
|
|
DebugLoc dl) {
|
2006-01-28 08:25:58 +00:00
|
|
|
// First step, figure out the appropriate FP_TO*INT operation to use.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewOutTy = DestVT;
|
2005-01-23 04:42:50 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
unsigned OpToUse = 0;
|
2005-04-13 05:09:42 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
2008-06-06 12:08:01 +00:00
|
|
|
NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1);
|
|
|
|
assert(NewOutTy.isInteger() && "Ran out of possibilities!");
|
2005-05-13 04:45:13 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// If the target supports FP_TO_SINT returning this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewOutTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::FP_TO_SINT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
2005-04-13 05:09:42 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// If the target supports FP_TO_UINT of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewOutTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::FP_TO_UINT;
|
|
|
|
break;
|
2005-04-13 05:09:42 +00:00
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
if (OpToUse) break;
|
2005-05-11 19:02:11 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// Otherwise, try a larger type.
|
2005-05-14 05:33:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
// Okay, we found the operation and type to use.
|
2009-02-02 19:03:57 +00:00
|
|
|
SDValue Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp);
|
2008-07-04 11:47:58 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
// If the operation produces an invalid type, it must be custom lowered. Use
|
|
|
|
// the target lowering hooks to expand it. Just keep the low part of the
|
|
|
|
// expanded operation, we know that we're truncating anyway.
|
|
|
|
if (getTypeAction(NewOutTy) == Expand) {
|
2008-12-01 11:39:25 +00:00
|
|
|
SmallVector<SDValue, 2> Results;
|
|
|
|
TLI.ReplaceNodeResults(Operation.getNode(), Results, DAG);
|
|
|
|
assert(Results.size() == 1 && "Incorrect FP_TO_XINT lowering!");
|
|
|
|
Operation = Results[0];
|
2007-11-24 07:07:01 +00:00
|
|
|
}
|
2008-07-04 11:47:58 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
// Truncate the result of the extended FP_TO_*INT operation to the desired
|
|
|
|
// size.
|
2009-02-02 19:03:57 +00:00
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, DestVT, Operation);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
2005-05-12 07:00:44 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// ExpandBSWAP - Open code the operations for BSWAP of the specified operation.
|
|
|
|
///
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandBSWAP(SDValue Op, DebugLoc dl) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT SHVT = TLI.getShiftAmountTy();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8;
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (VT.getSimpleVT()) {
|
2006-01-28 08:25:58 +00:00
|
|
|
default: assert(0 && "Unhandled Expand type in BSWAP!"); abort();
|
|
|
|
case MVT::i16:
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
return DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2);
|
2006-01-28 08:25:58 +00:00
|
|
|
case MVT::i32:
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp4 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::AND, dl, VT, Tmp3, DAG.getConstant(0xFF0000, VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::AND, dl, VT, Tmp2, DAG.getConstant(0xFF00, VT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp3);
|
|
|
|
Tmp2 = DAG.getNode(ISD::OR, dl, VT, Tmp2, Tmp1);
|
|
|
|
return DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp2);
|
2006-01-28 08:25:58 +00:00
|
|
|
case MVT::i64:
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp8 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(56, SHVT));
|
|
|
|
Tmp7 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(40, SHVT));
|
|
|
|
Tmp6 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp5 = DAG.getNode(ISD::SHL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(40, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, dl, VT, Op, DAG.getConstant(56, SHVT));
|
|
|
|
Tmp7 = DAG.getNode(ISD::AND, dl, VT, Tmp7, DAG.getConstant(255ULL<<48, VT));
|
|
|
|
Tmp6 = DAG.getNode(ISD::AND, dl, VT, Tmp6, DAG.getConstant(255ULL<<40, VT));
|
|
|
|
Tmp5 = DAG.getNode(ISD::AND, dl, VT, Tmp5, DAG.getConstant(255ULL<<32, VT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::AND, dl, VT, Tmp4, DAG.getConstant(255ULL<<24, VT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::AND, dl, VT, Tmp3, DAG.getConstant(255ULL<<16, VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::AND, dl, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT));
|
|
|
|
Tmp8 = DAG.getNode(ISD::OR, dl, VT, Tmp8, Tmp7);
|
|
|
|
Tmp6 = DAG.getNode(ISD::OR, dl, VT, Tmp6, Tmp5);
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp3);
|
|
|
|
Tmp2 = DAG.getNode(ISD::OR, dl, VT, Tmp2, Tmp1);
|
|
|
|
Tmp8 = DAG.getNode(ISD::OR, dl, VT, Tmp8, Tmp6);
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp2);
|
|
|
|
return DAG.getNode(ISD::OR, dl, VT, Tmp8, Tmp4);
|
2005-05-11 19:02:11 +00:00
|
|
|
}
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// ExpandBitCount - Expand the specified bitcount instruction into operations.
|
|
|
|
///
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDValue Op,
|
2009-02-02 22:12:50 +00:00
|
|
|
DebugLoc dl) {
|
2006-01-28 08:25:58 +00:00
|
|
|
switch (Opc) {
|
|
|
|
default: assert(0 && "Cannot expand this yet!");
|
|
|
|
case ISD::CTPOP: {
|
|
|
|
static const uint64_t mask[6] = {
|
|
|
|
0x5555555555555555ULL, 0x3333333333333333ULL,
|
|
|
|
0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
|
|
|
|
0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
|
|
|
|
};
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT ShVT = TLI.getShiftAmountTy();
|
|
|
|
unsigned len = VT.getSizeInBits();
|
2006-01-28 08:25:58 +00:00
|
|
|
for (unsigned i = 0; (1U << i) <= (len / 2); ++i) {
|
|
|
|
//x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8])
|
2009-02-01 18:06:53 +00:00
|
|
|
unsigned EltSize = VT.isVector() ?
|
|
|
|
VT.getVectorElementType().getSizeInBits() : len;
|
|
|
|
SDValue Tmp2 = DAG.getConstant(APInt(EltSize, mask[i]), VT);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT);
|
2009-02-17 22:15:04 +00:00
|
|
|
Op = DAG.getNode(ISD::ADD, dl, VT,
|
2009-02-06 21:55:48 +00:00
|
|
|
DAG.getNode(ISD::AND, dl, VT, Op, Tmp2),
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getNode(ISD::AND, dl, VT,
|
|
|
|
DAG.getNode(ISD::SRL, dl, VT, Op, Tmp3),
|
|
|
|
Tmp2));
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
case ISD::CTLZ: {
|
|
|
|
// for now, we do this:
|
|
|
|
// x = x | (x >> 1);
|
|
|
|
// x = x | (x >> 2);
|
|
|
|
// ...
|
|
|
|
// x = x | (x >>16);
|
|
|
|
// x = x | (x >>32); // for 64-bit input
|
|
|
|
// return popcount(~x);
|
|
|
|
//
|
|
|
|
// but see also: http://www.hackersdelight.org/HDcode/nlz.cc
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT ShVT = TLI.getShiftAmountTy();
|
|
|
|
unsigned len = VT.getSizeInBits();
|
2006-01-28 08:25:58 +00:00
|
|
|
for (unsigned i = 0; (1U << i) <= (len / 2); ++i) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp3 = DAG.getConstant(1ULL << i, ShVT);
|
2009-02-17 22:15:04 +00:00
|
|
|
Op = DAG.getNode(ISD::OR, dl, VT, Op,
|
2009-02-06 21:55:48 +00:00
|
|
|
DAG.getNode(ISD::SRL, dl, VT, Op, Tmp3));
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
2009-02-02 22:12:50 +00:00
|
|
|
Op = DAG.getNOT(dl, Op, VT);
|
|
|
|
return DAG.getNode(ISD::CTPOP, dl, VT, Op);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
case ISD::CTTZ: {
|
|
|
|
// for now, we use: { return popcount(~x & (x - 1)); }
|
|
|
|
// unless the target has ctlz but not ctpop, in which case we use:
|
|
|
|
// { return 32 - nlz(~x & (x-1)); }
|
|
|
|
// see also http://www.hackersdelight.org/HDcode/ntz.cc
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Tmp3 = DAG.getNode(ISD::AND, dl, VT,
|
|
|
|
DAG.getNOT(dl, Op, VT),
|
|
|
|
DAG.getNode(ISD::SUB, dl, VT, Op,
|
2009-01-30 23:03:19 +00:00
|
|
|
DAG.getConstant(1, VT)));
|
2006-01-28 08:25:58 +00:00
|
|
|
// If ISD::CTLZ is legal and CTPOP isn't, then do that instead.
|
2009-01-28 17:46:25 +00:00
|
|
|
if (!TLI.isOperationLegalOrCustom(ISD::CTPOP, VT) &&
|
|
|
|
TLI.isOperationLegalOrCustom(ISD::CTLZ, VT))
|
2009-02-02 22:12:50 +00:00
|
|
|
return DAG.getNode(ISD::SUB, dl, VT,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(VT.getSizeInBits(), VT),
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getNode(ISD::CTLZ, dl, VT, Tmp3));
|
|
|
|
return DAG.getNode(ISD::CTPOP, dl, VT, Tmp3);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
/// ExpandOp - Expand the specified SDValue into its two component pieces
|
2005-01-07 07:47:09 +00:00
|
|
|
/// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the
|
2008-10-01 15:07:49 +00:00
|
|
|
/// LegalizedNodes map is filled in for any results that are not expanded, the
|
2005-01-07 07:47:09 +00:00
|
|
|
/// ExpandedNodes map is filled in for any results that are expanded, and the
|
|
|
|
/// Lo/Hi values are returned.
|
2008-07-27 21:46:04 +00:00
|
|
|
void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT NVT = TLI.getTypeToTransformTo(VT);
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-02 22:12:50 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(getTypeAction(VT) == Expand && "Not an expanded type!");
|
2008-06-08 20:54:56 +00:00
|
|
|
assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() ||
|
2008-06-06 12:08:01 +00:00
|
|
|
VT.isVector()) && "Cannot expand to FP value or to larger int value!");
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-09-02 20:32:45 +00:00
|
|
|
// See if we already expanded it.
|
2008-07-27 21:46:04 +00:00
|
|
|
DenseMap<SDValue, std::pair<SDValue, SDValue> >::iterator I
|
2005-09-02 20:32:45 +00:00
|
|
|
= ExpandedNodes.find(Op);
|
|
|
|
if (I != ExpandedNodes.end()) {
|
|
|
|
Lo = I->second.first;
|
|
|
|
Hi = I->second.second;
|
|
|
|
return;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Node->getOpcode()) {
|
2006-01-21 04:27:00 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
assert(0 && "CopyFromReg must be legal!");
|
2007-10-10 01:01:31 +00:00
|
|
|
case ISD::FP_ROUND_INREG:
|
2009-02-17 22:15:04 +00:00
|
|
|
if (VT == MVT::ppcf128 &&
|
|
|
|
TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) ==
|
2007-10-10 01:01:31 +00:00
|
|
|
TargetLowering::Custom) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SrcLo, SrcHi, Src;
|
2007-10-11 23:32:15 +00:00
|
|
|
ExpandOp(Op.getOperand(0), SrcLo, SrcHi);
|
2009-02-02 22:12:50 +00:00
|
|
|
Src = DAG.getNode(ISD::BUILD_PAIR, dl, VT, SrcLo, SrcHi);
|
2009-04-10 18:48:47 +00:00
|
|
|
SDValue Result =
|
|
|
|
TLI.LowerOperation(DAG.getNode(ISD::FP_ROUND_INREG, dl, VT, Src,
|
|
|
|
Op.getOperand(1)), DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR);
|
|
|
|
Lo = Result.getNode()->getOperand(0);
|
|
|
|
Hi = Result.getNode()->getOperand(1);
|
2007-10-10 01:01:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through
|
2006-01-21 04:27:00 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(0 && "Do not know how to expand this operator!");
|
|
|
|
abort();
|
2008-02-27 01:52:30 +00:00
|
|
|
case ISD::EXTRACT_ELEMENT:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2008-09-12 16:56:44 +00:00
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getZExtValue())
|
2008-02-27 01:52:30 +00:00
|
|
|
return ExpandOp(Hi, Lo, Hi);
|
2008-02-27 19:44:57 +00:00
|
|
|
return ExpandOp(Lo, Lo, Hi);
|
2007-10-31 00:32:36 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
|
|
|
// ExpandEXTRACT_VECTOR_ELT tolerates invalid result types.
|
|
|
|
Lo = ExpandEXTRACT_VECTOR_ELT(Op);
|
|
|
|
return ExpandOp(Lo, Lo, Hi);
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF:
|
2009-02-06 23:05:02 +00:00
|
|
|
Lo = DAG.getUNDEF(NVT);
|
|
|
|
Hi = DAG.getUNDEF(NVT);
|
2005-04-01 22:34:39 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::Constant: {
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NVTBits = NVT.getSizeInBits();
|
2008-03-03 22:20:46 +00:00
|
|
|
const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue();
|
|
|
|
Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT);
|
|
|
|
Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-12 21:32:44 +00:00
|
|
|
case ISD::ConstantFP: {
|
|
|
|
ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node);
|
2007-10-11 18:07:22 +00:00
|
|
|
if (CFP->getValueType(0) == MVT::ppcf128) {
|
2008-10-09 18:53:47 +00:00
|
|
|
APInt api = CFP->getValueAPF().bitcastToAPInt();
|
2007-10-11 18:07:22 +00:00
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])),
|
|
|
|
MVT::f64);
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])),
|
2007-10-11 18:07:22 +00:00
|
|
|
MVT::f64);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 22:19:28 +00:00
|
|
|
Lo = ExpandConstantFP(CFP, false, DAG, TLI);
|
2006-12-13 20:57:08 +00:00
|
|
|
if (getTypeAction(Lo.getValueType()) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 21:32:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-03-28 22:03:13 +00:00
|
|
|
case ISD::BUILD_PAIR:
|
2006-01-28 05:07:51 +00:00
|
|
|
// Return the operands.
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
2005-03-28 22:03:13 +00:00
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
case ISD::MERGE_VALUES:
|
2007-11-24 19:12:15 +00:00
|
|
|
if (Node->getNumValues() == 1) {
|
|
|
|
ExpandOp(Op.getOperand(0), Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2007-11-24 07:07:01 +00:00
|
|
|
// FIXME: For now only expand i64,chain = MERGE_VALUES (x, y)
|
2008-08-26 22:36:50 +00:00
|
|
|
assert(Op.getResNo() == 0 && Node->getNumValues() == 2 &&
|
2007-11-24 07:07:01 +00:00
|
|
|
Op.getValue(1).getValueType() == MVT::Other &&
|
|
|
|
"unhandled MERGE_VALUES");
|
|
|
|
ExpandOp(Op.getOperand(0), Lo, Hi);
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1)));
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-12 22:27:43 +00:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2006-10-06 17:34:12 +00:00
|
|
|
// sext_inreg the low part if needed.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, NVT, Lo, Node->getOperand(1));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-10-06 17:34:12 +00:00
|
|
|
// The high part gets the sign extension from the lo-part. This handles
|
|
|
|
// things like sextinreg V:i64 from i8.
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, Lo,
|
2008-06-06 12:08:01 +00:00
|
|
|
DAG.getConstant(NVT.getSizeInBits()-1,
|
2005-12-12 22:27:43 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
|
|
|
break;
|
2005-03-28 22:03:13 +00:00
|
|
|
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP: {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue TempLo = DAG.getNode(ISD::BSWAP, dl, NVT, Hi);
|
|
|
|
Hi = DAG.getNode(ISD::BSWAP, dl, NVT, Lo);
|
2006-01-14 03:14:10 +00:00
|
|
|
Lo = TempLo;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-05-11 04:51:16 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADD, dl, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L)
|
|
|
|
DAG.getNode(ISD::CTPOP, dl, NVT, Lo),
|
|
|
|
DAG.getNode(ISD::CTPOP, dl, NVT, Hi));
|
2005-05-11 04:51:16 +00:00
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
|
2005-05-12 19:05:01 +00:00
|
|
|
case ISD::CTLZ: {
|
|
|
|
// ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32)
|
2005-05-12 19:27:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue HLZ = DAG.getNode(ISD::CTLZ, dl, NVT, Hi);
|
|
|
|
SDValue TopNotZero = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT), HLZ,
|
|
|
|
BitsC, ISD::SETNE);
|
|
|
|
SDValue LowPart = DAG.getNode(ISD::CTLZ, dl, NVT, Lo);
|
|
|
|
LowPart = DAG.getNode(ISD::ADD, dl, NVT, LowPart, BitsC);
|
2005-05-12 19:05:01 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT, dl, NVT, TopNotZero, HLZ, LowPart);
|
2005-05-12 19:05:01 +00:00
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::CTTZ: {
|
|
|
|
// cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32)
|
2005-05-12 19:27:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue BitsC = DAG.getConstant(NVT.getSizeInBits(), NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue LTZ = DAG.getNode(ISD::CTTZ, dl, NVT, Lo);
|
|
|
|
SDValue BotNotZero = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT), LTZ,
|
|
|
|
BitsC, ISD::SETNE);
|
|
|
|
SDValue HiPart = DAG.getNode(ISD::CTTZ, dl, NVT, Hi);
|
|
|
|
HiPart = DAG.getNode(ISD::ADD, dl, NVT, HiPart, BitsC);
|
2005-05-12 19:05:01 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT, dl, NVT, BotNotZero, LTZ, HiPart);
|
2005-05-12 19:05:01 +00:00
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-11 04:51:16 +00:00
|
|
|
|
2006-01-25 18:21:52 +00:00
|
|
|
case ISD::VAARG: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ch = Node->getOperand(0); // Legalize the chain.
|
|
|
|
SDValue Ptr = Node->getOperand(1); // Legalize the pointer.
|
2009-02-04 00:13:36 +00:00
|
|
|
Lo = DAG.getVAArg(NVT, dl, Ch, Ptr, Node->getOperand(2));
|
|
|
|
Hi = DAG.getVAArg(NVT, dl, Lo.getValue(1), Ptr, Node->getOperand(2));
|
2006-01-25 18:21:52 +00:00
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 05:07:51 +00:00
|
|
|
Hi = LegalizeOp(Hi);
|
2006-01-25 18:21:52 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), Hi.getValue(1));
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2006-01-25 18:21:52 +00:00
|
|
|
std::swap(Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::LOAD: {
|
2006-10-09 20:57:25 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ch = LD->getChain(); // Legalize the chain.
|
|
|
|
SDValue Ptr = LD->getBasePtr(); // Legalize the pointer.
|
2006-10-09 20:57:25 +00:00
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
2008-08-14 20:04:46 +00:00
|
|
|
const Value *SV = LD->getSrcValue();
|
2007-07-09 22:18:38 +00:00
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
if (ExtType == ISD::NON_EXTLOAD) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getLoad(NVT, dl, Ch, Ptr, SV, SVOffset,
|
2007-07-09 22:18:38 +00:00
|
|
|
isVolatile, Alignment);
|
2006-12-12 21:32:44 +00:00
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
|
|
|
// f32->i32 or f64->i64 one to one expansion.
|
|
|
|
// Remember that we legalized the chain.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1)));
|
2006-12-13 20:57:08 +00:00
|
|
|
// Recursively expand the new load.
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 21:32:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Increment the pointer to the other half.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned IncrementSize = Lo.getValueType().getSizeInBits()/8;
|
2009-02-02 22:12:50 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2007-06-25 16:23:39 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getLoad(NVT, dl, Ch, Ptr, SV, SVOffset,
|
2007-07-09 22:18:38 +00:00
|
|
|
isVolatile, Alignment);
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
|
2009-04-10 18:48:47 +00:00
|
|
|
Hi.getValue(1));
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF));
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2006-10-09 20:57:25 +00:00
|
|
|
std::swap(Lo, Hi);
|
|
|
|
} else {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT EVT = LD->getMemoryVT();
|
2006-12-13 03:19:57 +00:00
|
|
|
|
2007-10-19 20:29:00 +00:00
|
|
|
if ((VT == MVT::f64 && EVT == MVT::f32) ||
|
|
|
|
(VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) {
|
2006-12-13 03:19:57 +00:00
|
|
|
// f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Load = DAG.getLoad(EVT, dl, Ch, Ptr, SV,
|
2009-04-10 18:48:47 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-12-13 03:19:57 +00:00
|
|
|
// Remember that we legalized the chain.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Load.getValue(1)));
|
2009-02-02 22:12:50 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::FP_EXTEND, dl, VT, Load), Lo, Hi);
|
2006-12-13 03:19:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
if (EVT == NVT)
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getLoad(NVT, dl, Ch, Ptr, SV,
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-09 20:57:25 +00:00
|
|
|
else
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getExtLoad(ExtType, dl, NVT, Ch, Ptr, SV,
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, EVT, isVolatile,
|
|
|
|
Alignment);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
// Remember that we legalized the chain.
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Lo.getValue(1)));
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
if (ExtType == ISD::SEXTLOAD) {
|
|
|
|
// The high part is obtained by SRA'ing all but one of the bits of the
|
|
|
|
// lo part.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned LoSize = Lo.getValueType().getSizeInBits();
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, Lo,
|
2006-10-09 20:57:25 +00:00
|
|
|
DAG.getConstant(LoSize-1, TLI.getShiftAmountTy()));
|
|
|
|
} else if (ExtType == ISD::ZEXTLOAD) {
|
|
|
|
// The high part is just a zero.
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else /* if (ExtType == ISD::EXTLOAD) */ {
|
|
|
|
// The high part is undefined.
|
2009-02-06 23:05:02 +00:00
|
|
|
Hi = DAG.getUNDEF(NVT);
|
2006-10-09 20:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR: { // Simple logical operators -> two trivial pieces.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2005-01-07 07:47:09 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(1), RL, RH);
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NVT, LH, RH);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::SELECT: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2005-01-07 07:47:09 +00:00
|
|
|
ExpandOp(Node->getOperand(1), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(2), RL, RH);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
NVT = TLI.getTypeToExpandTo(NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT, dl, NVT, Node->getOperand(0), LL, RL);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (VT != MVT::f32)
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SELECT, dl, NVT, Node->getOperand(0), LH, RH);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-10 20:51:12 +00:00
|
|
|
case ISD::SELECT_CC: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue TL, TH, FL, FH;
|
2005-08-10 20:51:12 +00:00
|
|
|
ExpandOp(Node->getOperand(2), TL, TH);
|
|
|
|
ExpandOp(Node->getOperand(3), FL, FH);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
NVT = TLI.getTypeToExpandTo(NVT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT_CC, dl, NVT, Node->getOperand(0),
|
2005-08-10 20:51:12 +00:00
|
|
|
Node->getOperand(1), TL, FL, Node->getOperand(4));
|
2006-12-15 22:42:55 +00:00
|
|
|
if (VT != MVT::f32)
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SELECT_CC, dl, NVT, Node->getOperand(0),
|
2006-12-15 22:42:55 +00:00
|
|
|
Node->getOperand(1), TH, FH, Node->getOperand(4));
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-09-02 00:18:10 +00:00
|
|
|
// The low part is any extension of the input (which degenerates to a copy).
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ANY_EXTEND, dl, NVT, Node->getOperand(0));
|
2005-09-02 00:18:10 +00:00
|
|
|
// The high part is undefined.
|
2009-02-06 23:05:02 +00:00
|
|
|
Hi = DAG.getUNDEF(NVT);
|
2005-09-02 00:18:10 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::SIGN_EXTEND: {
|
|
|
|
// The low part is just a sign extension of the input (which degenerates to
|
|
|
|
// a copy).
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SIGN_EXTEND, dl, NVT, Node->getOperand(0));
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// The high part is obtained by SRA'ing all but one of the bits of the lo
|
|
|
|
// part.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned LoSize = Lo.getValueType().getSizeInBits();
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, dl, NVT, Lo,
|
2006-01-28 05:07:51 +00:00
|
|
|
DAG.getConstant(LoSize-1, TLI.getShiftAmountTy()));
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
2005-01-07 07:47:09 +00:00
|
|
|
// The low part is just a zero extension of the input (which degenerates to
|
|
|
|
// a copy).
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Node->getOperand(0));
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// The high part is just a zero.
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-02-13 23:55:16 +00:00
|
|
|
case ISD::TRUNCATE: {
|
|
|
|
// The input value must be larger than this value. Expand *it*.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue NewLo;
|
2007-02-13 23:55:16 +00:00
|
|
|
ExpandOp(Node->getOperand(0), NewLo, Hi);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-02-13 23:55:16 +00:00
|
|
|
// The low part is now either the right size, or it is closer. If not the
|
|
|
|
// right size, make an illegal truncate so we recursively expand it.
|
|
|
|
if (NewLo.getValueType() != Node->getValueType(0))
|
2009-02-02 22:12:50 +00:00
|
|
|
NewLo = DAG.getNode(ISD::TRUNCATE, dl, Node->getValueType(0), NewLo);
|
2007-02-13 23:55:16 +00:00
|
|
|
ExpandOp(NewLo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp;
|
2006-09-09 00:20:27 +00:00
|
|
|
if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){
|
|
|
|
// If the target wants to, allow it to lower this itself.
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
|
|
|
case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Tmp = PromoteOp (Node->getOperand(0)); break;
|
|
|
|
}
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, dl, VT, Tmp), DAG);
|
2006-09-09 00:20:27 +00:00
|
|
|
}
|
|
|
|
|
2006-12-09 02:42:38 +00:00
|
|
|
// f32 / f64 must be expanded to i32 / i64.
|
2006-12-11 19:27:14 +00:00
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Node->getOperand(0));
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 19:53:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If source operand will be expanded to the same type as VT, i.e.
|
|
|
|
// i64 <- f64, i32 <- f32, expand the source operand instead.
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT0 = Node->getOperand(0).getValueType();
|
2006-12-12 19:53:13 +00:00
|
|
|
if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-09-09 00:20:27 +00:00
|
|
|
// Turn this into a load/store pair by default.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Tmp.getNode() == 0)
|
2009-02-02 22:12:50 +00:00
|
|
|
Tmp = EmitStackConvert(Node->getOperand(0), VT, VT, dl);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-12-23 00:16:34 +00:00
|
|
|
ExpandOp(Tmp, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
case ISD::READCYCLECOUNTER: {
|
2009-02-17 22:15:04 +00:00
|
|
|
assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) ==
|
2005-11-20 22:56:56 +00:00
|
|
|
TargetLowering::Custom &&
|
|
|
|
"Must custom expand ReadCycleCounter");
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
assert(Tmp.getNode() && "Node must be custom expanded!");
|
2007-11-24 07:07:01 +00:00
|
|
|
ExpandOp(Tmp.getValue(0), Lo, Hi);
|
2008-07-27 21:46:04 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain.
|
2007-11-24 07:07:01 +00:00
|
|
|
LegalizeOp(Tmp.getValue(1)));
|
2005-11-20 21:32:07 +00:00
|
|
|
break;
|
2007-11-24 07:07:01 +00:00
|
|
|
}
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_CMP_SWAP: {
|
2008-10-03 19:41:08 +00:00
|
|
|
// This operation does not need a loop.
|
|
|
|
SDValue Tmp = TLI.LowerOperation(Op, DAG);
|
|
|
|
assert(Tmp.getNode() && "Node must be custom expanded!");
|
|
|
|
ExpandOp(Tmp.getValue(0), Lo, Hi);
|
|
|
|
AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain.
|
|
|
|
LegalizeOp(Tmp.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_LOAD_ADD:
|
|
|
|
case ISD::ATOMIC_LOAD_SUB:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_NAND:
|
|
|
|
case ISD::ATOMIC_SWAP: {
|
2008-10-03 19:41:08 +00:00
|
|
|
// These operations require a loop to be generated. We can't do that yet,
|
|
|
|
// so substitute a target-dependent pseudo and expand that later.
|
2008-10-02 18:53:47 +00:00
|
|
|
SDValue In2Lo, In2Hi, In2;
|
|
|
|
ExpandOp(Op.getOperand(2), In2Lo, In2Hi);
|
2009-02-02 22:12:50 +00:00
|
|
|
In2 = DAG.getNode(ISD::BUILD_PAIR, dl, VT, In2Lo, In2Hi);
|
2008-10-03 19:41:08 +00:00
|
|
|
AtomicSDNode* Anode = cast<AtomicSDNode>(Node);
|
2009-02-17 22:15:04 +00:00
|
|
|
SDValue Replace =
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getAtomic(Op.getOpcode(), dl, Anode->getMemoryVT(),
|
2008-12-23 21:37:04 +00:00
|
|
|
Op.getOperand(0), Op.getOperand(1), In2,
|
2008-10-03 19:41:08 +00:00
|
|
|
Anode->getSrcValue(), Anode->getAlignment());
|
|
|
|
SDValue Result = TLI.LowerOperation(Replace, DAG);
|
2008-10-02 18:53:47 +00:00
|
|
|
ExpandOp(Result.getValue(0), Lo, Hi);
|
|
|
|
// Remember that we legalized the chain.
|
2009-04-10 18:48:47 +00:00
|
|
|
AddLegalizedOperand(SDValue(Node, 1), LegalizeOp(Result.getValue(1)));
|
2008-03-05 01:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-08 19:27:05 +00:00
|
|
|
// These operators cannot be expanded directly, emit them as calls to
|
|
|
|
// library functions.
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FP_TO_SINT: {
|
2005-07-29 00:33:32 +00:00
|
|
|
if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op;
|
2005-07-30 01:40:57 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
2006-01-28 05:07:51 +00:00
|
|
|
case Legal: Op = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Op = PromoteOp (Node->getOperand(0)); break;
|
2005-07-30 01:40:57 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, dl, VT, Op), DAG);
|
2005-07-30 01:40:57 +00:00
|
|
|
|
2005-07-29 00:33:32 +00:00
|
|
|
// Now that the custom expander is done, expand the result, which is still
|
|
|
|
// VT.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op.getNode()) {
|
2005-08-26 00:14:16 +00:00
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-29 00:33:32 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2008-07-17 02:36:29 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::getFPTOSINT(Node->getOperand(0).getValueType(),
|
|
|
|
VT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected uint-to-fp conversion!");
|
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2005-01-08 19:27:05 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FP_TO_UINT: {
|
2005-07-29 00:33:32 +00:00
|
|
|
if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op;
|
2006-01-28 05:07:51 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
|
|
|
case Legal: Op = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Op = PromoteOp (Node->getOperand(0)); break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, dl, VT, Op), DAG);
|
2006-01-28 05:07:51 +00:00
|
|
|
|
|
|
|
// Now that the custom expander is done, expand the result.
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op.getNode()) {
|
2005-08-26 00:14:16 +00:00
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-29 00:33:32 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2008-07-17 02:36:29 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::getFPTOUINT(Node->getOperand(0).getValueType(),
|
|
|
|
VT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fp-to-uint conversion!");
|
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2005-01-08 19:27:05 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
}
|
2005-01-08 19:27:05 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
case ISD::SHL: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) {
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Op = DAG.getNode(ISD::SHL, dl, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op.getNode()) {
|
2005-08-31 19:01:53 +00:00
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// If ADDC/ADDE are supported and if the shift amount is a constant 1, emit
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
// this X << 1 as X+X.
|
|
|
|
if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) {
|
2009-01-28 17:46:25 +00:00
|
|
|
if (ShAmt->getAPIntValue() == 1 &&
|
2009-02-17 22:15:04 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::ADDC, NVT) &&
|
2009-01-28 17:46:25 +00:00
|
|
|
TLI.isOperationLegalOrCustom(ISD::ADDE, NVT)) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LoOps[2], HiOps[3];
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]);
|
|
|
|
SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag);
|
|
|
|
LoOps[1] = LoOps[0];
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADDC, dl, VTList, LoOps, 2);
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
|
|
|
|
HiOps[1] = HiOps[0];
|
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::ADDE, dl, VTList, HiOps, 3);
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2009-02-02 22:12:50 +00:00
|
|
|
if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi, dl))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SHL_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SHL_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2009-02-17 22:15:04 +00:00
|
|
|
ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0),
|
2009-02-02 22:12:50 +00:00
|
|
|
ShiftAmt, Lo, Hi, dl);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
case ISD::SRA: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) {
|
2009-02-06 21:55:48 +00:00
|
|
|
SDValue Op = DAG.getNode(ISD::SRA, dl, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op.getNode()) {
|
2005-08-31 19:01:53 +00:00
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2009-02-02 22:12:50 +00:00
|
|
|
if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi, dl))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SRA_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SRA_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2009-02-17 22:15:04 +00:00
|
|
|
ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0),
|
2009-02-02 22:12:50 +00:00
|
|
|
ShiftAmt, Lo, Hi, dl);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::SRL: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) {
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Op = DAG.getNode(ISD::SRL, dl, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op.getNode()) {
|
2005-08-31 19:01:53 +00:00
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2009-02-02 22:12:50 +00:00
|
|
|
if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi, dl))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SRL_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SRL_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2009-02-02 22:12:50 +00:00
|
|
|
ExpandShiftParts(ISD::SRL_PARTS,
|
|
|
|
Node->getOperand(0), ShiftAmt, Lo, Hi, dl);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2005-04-21 22:36:52 +00:00
|
|
|
case ISD::ADD:
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::SUB: {
|
|
|
|
// If the target wants to custom expand this, let them.
|
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), VT) ==
|
|
|
|
TargetLowering::Custom) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Result = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) {
|
2008-06-22 09:42:16 +00:00
|
|
|
ExpandOp(Result, Lo, Hi);
|
2006-01-28 05:07:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Expand the subcomponents.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LHSL, LHSH, RHSL, RHSH;
|
2006-01-28 05:07:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LoOps[2], HiOps[3];
|
2006-08-08 02:23:42 +00:00
|
|
|
LoOps[0] = LHSL;
|
|
|
|
LoOps[1] = RHSL;
|
|
|
|
HiOps[0] = LHSH;
|
|
|
|
HiOps[1] = RHSH;
|
2008-10-07 18:27:23 +00:00
|
|
|
|
2008-10-07 17:03:15 +00:00
|
|
|
//cascaded check to see if any smaller size has a a carry flag.
|
|
|
|
unsigned OpV = Node->getOpcode() == ISD::ADD ? ISD::ADDC : ISD::SUBC;
|
|
|
|
bool hasCarry = false;
|
2008-10-07 18:27:23 +00:00
|
|
|
for (unsigned BitSize = NVT.getSizeInBits(); BitSize != 0; BitSize /= 2) {
|
|
|
|
MVT AVT = MVT::getIntegerVT(BitSize);
|
2009-01-28 17:46:25 +00:00
|
|
|
if (TLI.isOperationLegalOrCustom(OpV, AVT)) {
|
2008-10-07 18:27:23 +00:00
|
|
|
hasCarry = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 17:03:15 +00:00
|
|
|
if(hasCarry) {
|
2008-12-12 18:49:09 +00:00
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
2008-10-07 14:15:42 +00:00
|
|
|
if (Node->getOpcode() == ISD::ADD) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADDC, dl, VTList, LoOps, 2);
|
2008-10-07 14:15:42 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::ADDE, dl, VTList, HiOps, 3);
|
2008-10-07 14:15:42 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SUBC, dl, VTList, LoOps, 2);
|
2008-10-07 14:15:42 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SUBE, dl, VTList, HiOps, 3);
|
2008-10-07 14:15:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-02-17 05:43:56 +00:00
|
|
|
} else {
|
2008-10-07 14:15:42 +00:00
|
|
|
if (Node->getOpcode() == ISD::ADD) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADD, dl, NVT, LoOps, 2);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, HiOps, 2);
|
|
|
|
SDValue Cmp1 = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT),
|
2008-10-07 17:03:15 +00:00
|
|
|
Lo, LoOps[0], ISD::SETULT);
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Carry1 = DAG.getNode(ISD::SELECT, dl, NVT, Cmp1,
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getConstant(1, NVT),
|
2008-10-07 14:15:42 +00:00
|
|
|
DAG.getConstant(0, NVT));
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Cmp2 = DAG.getSetCC(dl, TLI.getSetCCResultType(NVT),
|
2008-10-07 17:03:15 +00:00
|
|
|
Lo, LoOps[1], ISD::SETULT);
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue Carry2 = DAG.getNode(ISD::SELECT, dl, NVT, Cmp2,
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getConstant(1, NVT),
|
2008-10-07 14:15:42 +00:00
|
|
|
Carry1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, Carry2);
|
2008-10-07 14:15:42 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SUB, dl, NVT, LoOps, 2);
|
|
|
|
Hi = DAG.getNode(ISD::SUB, dl, NVT, HiOps, 2);
|
|
|
|
SDValue Cmp = DAG.getSetCC(dl, NVT, LoOps[0], LoOps[1], ISD::SETULT);
|
|
|
|
SDValue Borrow = DAG.getNode(ISD::SELECT, dl, NVT, Cmp,
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getConstant(1, NVT),
|
2008-10-07 14:15:42 +00:00
|
|
|
DAG.getConstant(0, NVT));
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SUB, dl, NVT, Hi, Borrow);
|
2008-10-07 14:15:42 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-02-17 05:43:56 +00:00
|
|
|
}
|
2006-01-28 05:07:51 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-05-17 18:15:41 +00:00
|
|
|
case ISD::ADDC:
|
|
|
|
case ISD::SUBC: {
|
|
|
|
// Expand the subcomponents.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LHSL, LHSH, RHSL, RHSH;
|
2007-05-17 18:15:41 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LoOps[2] = { LHSL, RHSL };
|
|
|
|
SDValue HiOps[3] = { LHSH, RHSH };
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-05-17 18:15:41 +00:00
|
|
|
if (Node->getOpcode() == ISD::ADDC) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADDC, dl, VTList, LoOps, 2);
|
2007-05-17 18:15:41 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::ADDE, dl, VTList, HiOps, 3);
|
2007-05-17 18:15:41 +00:00
|
|
|
} else {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SUBC, dl, VTList, LoOps, 2);
|
2007-05-17 18:15:41 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::SUBE, dl, VTList, HiOps, 3);
|
2007-05-17 18:15:41 +00:00
|
|
|
}
|
|
|
|
// Remember that we legalized the flag.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::ADDE:
|
|
|
|
case ISD::SUBE: {
|
|
|
|
// Expand the subcomponents.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LHSL, LHSH, RHSL, RHSH;
|
2007-05-17 18:15:41 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LoOps[3] = { LHSL, RHSL, Node->getOperand(2) };
|
|
|
|
SDValue HiOps[3] = { LHSH, RHSH };
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, VTList, LoOps, 3);
|
2007-05-17 18:15:41 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, VTList, HiOps, 3);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-05-17 18:15:41 +00:00
|
|
|
// Remember that we legalized the flag.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 03:01:51 +00:00
|
|
|
case ISD::MUL: {
|
2006-09-16 00:09:24 +00:00
|
|
|
// If the target wants to custom expand this, let them.
|
|
|
|
if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue New = TLI.LowerOperation(Op, DAG);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (New.getNode()) {
|
2006-09-16 05:08:34 +00:00
|
|
|
ExpandOp(New, Lo, Hi);
|
2006-09-16 00:09:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-01-28 17:46:25 +00:00
|
|
|
bool HasMULHS = TLI.isOperationLegalOrCustom(ISD::MULHS, NVT);
|
|
|
|
bool HasMULHU = TLI.isOperationLegalOrCustom(ISD::MULHU, NVT);
|
|
|
|
bool HasSMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::SMUL_LOHI, NVT);
|
|
|
|
bool HasUMUL_LOHI = TLI.isOperationLegalOrCustom(ISD::UMUL_LOHI, NVT);
|
2007-10-08 18:33:35 +00:00
|
|
|
if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2005-04-11 03:01:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(1), RL, RH);
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned OuterBitSize = Op.getValueSizeInBits();
|
|
|
|
unsigned InnerBitSize = RH.getValueSizeInBits();
|
2007-10-08 18:33:35 +00:00
|
|
|
unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0));
|
|
|
|
unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1));
|
2008-03-10 20:42:19 +00:00
|
|
|
APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize);
|
|
|
|
if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) {
|
2007-10-08 18:33:35 +00:00
|
|
|
// The inputs are both zero-extended.
|
|
|
|
if (HasUMUL_LOHI) {
|
|
|
|
// We can emit a umul_lohi.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::UMUL_LOHI, dl, DAG.getVTList(NVT, NVT), LL, RL);
|
2008-08-28 21:40:38 +00:00
|
|
|
Hi = SDValue(Lo.getNode(), 1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (HasMULHU) {
|
|
|
|
// We can emit a mulhu+mul.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::MUL, dl, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHU, dl, NVT, LL, RL);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) {
|
2007-10-08 18:33:35 +00:00
|
|
|
// The input values are both sign-extended.
|
|
|
|
if (HasSMUL_LOHI) {
|
|
|
|
// We can emit a smul_lohi.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SMUL_LOHI, dl, DAG.getVTList(NVT, NVT), LL, RL);
|
2008-08-28 21:40:38 +00:00
|
|
|
Hi = SDValue(Lo.getNode(), 1);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (HasMULHS) {
|
|
|
|
// We can emit a mulhs+mul.
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::MUL, dl, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHS, dl, NVT, LL, RL);
|
2007-10-08 18:33:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HasUMUL_LOHI) {
|
|
|
|
// Lo,Hi = umul LHS, RHS.
|
2009-02-02 22:12:50 +00:00
|
|
|
SDValue UMulLOHI = DAG.getNode(ISD::UMUL_LOHI, dl,
|
2007-10-08 18:33:35 +00:00
|
|
|
DAG.getVTList(NVT, NVT), LL, RL);
|
|
|
|
Lo = UMulLOHI;
|
|
|
|
Hi = UMulLOHI.getValue(1);
|
2009-02-02 22:12:50 +00:00
|
|
|
RH = DAG.getNode(ISD::MUL, dl, NVT, LL, RH);
|
|
|
|
LH = DAG.getNode(ISD::MUL, dl, NVT, LH, RL);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, RH);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, LH);
|
2006-09-16 00:21:44 +00:00
|
|
|
break;
|
Add support for AssertSext and AssertZext, folding other extensions with
them. This allows for elminination of redundant extends in the entry
blocks of functions on PowerPC.
Add support for i32 x i32 -> i64 multiplies, by recognizing when the inputs
to ISD::MUL in ExpandOp are actually just extended i32 values and not real
i64 values. this allows us to codegen
int mulhs(int a, int b) { return ((long long)a * b) >> 32; }
as:
_mulhs:
mulhw r3, r4, r3
blr
instead of:
_mulhs:
mulhwu r2, r4, r3
srawi r5, r3, 31
mullw r5, r4, r5
add r2, r2, r5
srawi r4, r4, 31
mullw r3, r4, r3
add r3, r2, r3
blr
with a similar improvement on x86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23147 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-30 02:44:00 +00:00
|
|
|
}
|
2007-10-24 22:26:08 +00:00
|
|
|
if (HasMULHU) {
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::MUL, dl, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHU, dl, NVT, LL, RL);
|
|
|
|
RH = DAG.getNode(ISD::MUL, dl, NVT, LL, RH);
|
|
|
|
LH = DAG.getNode(ISD::MUL, dl, NVT, LH, RL);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, RH);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, NVT, Hi, LH);
|
2007-10-24 22:26:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-04-11 03:01:51 +00:00
|
|
|
}
|
2006-09-01 18:17:58 +00:00
|
|
|
|
2007-10-08 18:33:35 +00:00
|
|
|
// If nothing else, we can make a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi);
|
2005-04-11 03:01:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::SDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::UDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::SREM:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::UREM:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2006-12-12 21:51:17 +00:00
|
|
|
|
2006-12-09 02:42:38 +00:00
|
|
|
case ISD::FADD:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32,
|
|
|
|
RTLIB::ADD_F64,
|
|
|
|
RTLIB::ADD_F80,
|
|
|
|
RTLIB::ADD_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSUB:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32,
|
|
|
|
RTLIB::SUB_F64,
|
|
|
|
RTLIB::SUB_F80,
|
|
|
|
RTLIB::SUB_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FMUL:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32,
|
|
|
|
RTLIB::MUL_F64,
|
|
|
|
RTLIB::MUL_F80,
|
|
|
|
RTLIB::MUL_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32,
|
|
|
|
RTLIB::DIV_F64,
|
|
|
|
RTLIB::DIV_F80,
|
|
|
|
RTLIB::DIV_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
2008-07-17 02:36:29 +00:00
|
|
|
case ISD::FP_EXTEND: {
|
2007-10-12 01:37:08 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
|
|
|
assert(Node->getOperand(0).getValueType()==MVT::f32 ||
|
|
|
|
Node->getOperand(0).getValueType()==MVT::f64);
|
|
|
|
const uint64_t zero = 0;
|
|
|
|
if (Node->getOperand(0).getValueType()==MVT::f32)
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Node->getOperand(0));
|
2007-10-12 01:37:08 +00:00
|
|
|
else
|
|
|
|
Hi = Node->getOperand(0);
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
|
|
|
break;
|
|
|
|
}
|
2008-07-17 02:36:29 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::getFPEXT(Node->getOperand(0).getValueType(), VT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
|
|
|
|
Lo = ExpandLibCall(LC, Node, true, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
2008-07-17 02:36:29 +00:00
|
|
|
}
|
|
|
|
case ISD::FP_ROUND: {
|
|
|
|
RTLIB::Libcall LC = RTLIB::getFPROUND(Node->getOperand(0).getValueType(),
|
|
|
|
VT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_ROUND!");
|
|
|
|
Lo = ExpandLibCall(LC, Node, true, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
2008-07-17 02:36:29 +00:00
|
|
|
}
|
2008-09-09 23:02:14 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
2009-02-17 22:15:04 +00:00
|
|
|
case ISD::FCOS:
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2008-08-21 18:38:14 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
case ISD::FCEIL:
|
|
|
|
case ISD::FRINT:
|
|
|
|
case ISD::FNEARBYINT:
|
2008-09-09 23:35:53 +00:00
|
|
|
case ISD::FPOW:
|
|
|
|
case ISD::FPOWI: {
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2006-12-13 02:38:13 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FSQRT:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
|
|
|
|
RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSIN:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64,
|
|
|
|
RTLIB::SIN_F80, RTLIB::SIN_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FCOS:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64,
|
|
|
|
RTLIB::COS_F80, RTLIB::COS_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG_F32, RTLIB::LOG_F64,
|
|
|
|
RTLIB::LOG_F80, RTLIB::LOG_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FLOG2:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG2_F32, RTLIB::LOG2_F64,
|
|
|
|
RTLIB::LOG2_F80, RTLIB::LOG2_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FLOG10:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::LOG10_F32, RTLIB::LOG10_F64,
|
|
|
|
RTLIB::LOG10_F80, RTLIB::LOG10_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FEXP:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::EXP_F32, RTLIB::EXP_F64,
|
|
|
|
RTLIB::EXP_F80, RTLIB::EXP_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FEXP2:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::EXP2_F32, RTLIB::EXP2_F64,
|
|
|
|
RTLIB::EXP2_F80, RTLIB::EXP2_PPCF128);
|
|
|
|
break;
|
2008-08-21 18:38:14 +00:00
|
|
|
case ISD::FTRUNC:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::TRUNC_F32, RTLIB::TRUNC_F64,
|
|
|
|
RTLIB::TRUNC_F80, RTLIB::TRUNC_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FFLOOR:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::FLOOR_F32, RTLIB::FLOOR_F64,
|
|
|
|
RTLIB::FLOOR_F80, RTLIB::FLOOR_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FCEIL:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::CEIL_F32, RTLIB::CEIL_F64,
|
|
|
|
RTLIB::CEIL_F80, RTLIB::CEIL_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FRINT:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::RINT_F32, RTLIB::RINT_F64,
|
|
|
|
RTLIB::RINT_F80, RTLIB::RINT_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FNEARBYINT:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::NEARBYINT_F32, RTLIB::NEARBYINT_F64,
|
|
|
|
RTLIB::NEARBYINT_F80, RTLIB::NEARBYINT_PPCF128);
|
|
|
|
break;
|
2008-09-09 23:02:14 +00:00
|
|
|
case ISD::FPOW:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80,
|
|
|
|
RTLIB::POW_PPCF128);
|
|
|
|
break;
|
|
|
|
case ISD::FPOWI:
|
|
|
|
LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64, RTLIB::POWI_F80,
|
|
|
|
RTLIB::POWI_PPCF128);
|
|
|
|
break;
|
2006-12-13 02:38:13 +00:00
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
}
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false, Hi);
|
2006-12-13 02:38:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-16 00:52:40 +00:00
|
|
|
case ISD::FABS: {
|
2007-10-12 19:02:17 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp;
|
2007-10-12 19:02:17 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Tmp);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::FABS, dl, NVT, Tmp);
|
2007-10-12 19:02:17 +00:00
|
|
|
// lo = hi==fabs(hi) ? lo : -lo;
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT_CC, dl, NVT, Hi, Tmp,
|
2009-04-10 18:48:47 +00:00
|
|
|
Lo, DAG.getNode(ISD::FNEG, dl, NVT, Lo),
|
|
|
|
DAG.getCondCode(ISD::SETEQ));
|
2007-10-12 19:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Mask = (VT == MVT::f64)
|
2006-12-16 00:52:40 +00:00
|
|
|
? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Mask = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Mask);
|
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Node->getOperand(0));
|
|
|
|
Lo = DAG.getNode(ISD::AND, dl, NVT, Lo, Mask);
|
2006-12-16 00:52:40 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::FNEG: {
|
2007-10-12 19:02:17 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2009-02-02 22:12:50 +00:00
|
|
|
Lo = DAG.getNode(ISD::FNEG, dl, MVT::f64, Lo);
|
|
|
|
Hi = DAG.getNode(ISD::FNEG, dl, MVT::f64, Hi);
|
2007-10-12 19:02:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Mask = (VT == MVT::f64)
|
2006-12-16 00:52:40 +00:00
|
|
|
? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(1U << 31), VT);
|
2009-02-02 22:12:50 +00:00
|
|
|
Mask = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Mask);
|
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NVT, Node->getOperand(0));
|
|
|
|
Lo = DAG.getNode(ISD::XOR, dl, NVT, Lo, Mask);
|
2006-12-16 00:52:40 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
case ISD::FCOPYSIGN: {
|
|
|
|
Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI);
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-19 01:44:04 +00:00
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP: {
|
|
|
|
bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT SrcVT = Node->getOperand(0).getValueType();
|
2008-03-18 17:28:38 +00:00
|
|
|
|
|
|
|
// Promote the operand if needed. Do this before checking for
|
|
|
|
// ppcf128 so conversions of i16 and i8 work.
|
|
|
|
if (getTypeAction(SrcVT) == Promote) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp = PromoteOp(Node->getOperand(0));
|
2008-03-18 17:28:38 +00:00
|
|
|
Tmp = isSigned
|
2009-02-02 22:12:50 +00:00
|
|
|
? DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, Tmp.getValueType(), Tmp,
|
2008-03-18 17:28:38 +00:00
|
|
|
DAG.getValueType(SrcVT))
|
2009-02-02 22:12:50 +00:00
|
|
|
: DAG.getZeroExtendInReg(Tmp, dl, SrcVT);
|
2008-08-28 21:40:38 +00:00
|
|
|
Node = DAG.UpdateNodeOperands(Op, Tmp).getNode();
|
2008-03-18 17:28:38 +00:00
|
|
|
SrcVT = Node->getOperand(0).getValueType();
|
|
|
|
}
|
|
|
|
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::ppcf128 && SrcVT == MVT::i32) {
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t zero = 0;
|
2007-10-12 01:37:08 +00:00
|
|
|
if (isSigned) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64,
|
2007-10-12 01:37:08 +00:00
|
|
|
Node->getOperand(0)));
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
|
|
|
} else {
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 };
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::f64,
|
2007-10-12 01:37:08 +00:00
|
|
|
Node->getOperand(0)));
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
2009-02-02 22:12:50 +00:00
|
|
|
Hi = DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi);
|
2007-10-12 17:52:03 +00:00
|
|
|
// X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32
|
2009-02-02 22:12:50 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::SELECT_CC, dl,
|
|
|
|
MVT::ppcf128, Node->getOperand(0),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getConstant(0, MVT::i32),
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getNode(ISD::FADD, dl, MVT::ppcf128, Hi,
|
2009-04-10 18:48:47 +00:00
|
|
|
DAG.getConstantFP
|
|
|
|
(APFloat(APInt(128, 2, TwoE32)),
|
|
|
|
MVT::ppcf128)),
|
2007-10-12 01:37:08 +00:00
|
|
|
Hi,
|
|
|
|
DAG.getCondCode(ISD::SETLT)),
|
|
|
|
Lo, Hi);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-12 17:52:03 +00:00
|
|
|
if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) {
|
|
|
|
// si64->ppcf128 done by libcall, below
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 };
|
2009-02-02 22:12:50 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::SINT_TO_FP, dl, MVT::ppcf128,
|
|
|
|
Node->getOperand(0)), Lo, Hi);
|
|
|
|
Hi = DAG.getNode(ISD::BUILD_PAIR, dl, VT, Lo, Hi);
|
2007-10-12 17:52:03 +00:00
|
|
|
// x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64
|
2009-02-02 22:12:50 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::SELECT_CC, dl, MVT::ppcf128,
|
|
|
|
Node->getOperand(0),
|
2009-02-17 22:15:04 +00:00
|
|
|
DAG.getConstant(0, MVT::i64),
|
2009-02-02 22:12:50 +00:00
|
|
|
DAG.getNode(ISD::FADD, dl, MVT::ppcf128, Hi,
|
2009-04-10 18:48:47 +00:00
|
|
|
DAG.getConstantFP
|
|
|
|
(APFloat(APInt(128, 2, TwoE64)),
|
|
|
|
MVT::ppcf128)),
|
2007-10-12 17:52:03 +00:00
|
|
|
Hi,
|
|
|
|
DAG.getCondCode(ISD::SETLT)),
|
|
|
|
Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-19 01:44:04 +00:00
|
|
|
|
2008-03-10 23:03:31 +00:00
|
|
|
Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT,
|
2009-02-02 22:12:50 +00:00
|
|
|
Node->getOperand(0), dl);
|
2008-04-01 01:50:16 +00:00
|
|
|
if (getTypeAction(Lo.getValueType()) == Expand)
|
2008-04-01 01:51:26 +00:00
|
|
|
// float to i32 etc. can be 'expanded' to a single node.
|
2008-04-01 01:50:16 +00:00
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-19 01:44:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-13 02:38:13 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-12-21 18:02:52 +00:00
|
|
|
// Make sure the resultant values have been legalized themselves, unless this
|
|
|
|
// is a type that requires multi-step expansion.
|
|
|
|
if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) {
|
|
|
|
Lo = LegalizeOp(Lo);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Hi.getNode())
|
2006-12-11 19:27:14 +00:00
|
|
|
// Don't legalize the high part if it is expanded to a single node.
|
|
|
|
Hi = LegalizeOp(Hi);
|
2005-12-21 18:02:52 +00:00
|
|
|
}
|
2006-01-09 18:31:59 +00:00
|
|
|
|
|
|
|
// Remember in a map if the values will be reused later.
|
2008-07-07 17:46:23 +00:00
|
|
|
bool isNew =
|
|
|
|
ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second;
|
2006-01-09 18:31:59 +00:00
|
|
|
assert(isNew && "Value already expanded?!?");
|
2008-11-24 07:09:49 +00:00
|
|
|
isNew = isNew;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// SplitVectorOp - Given an operand of vector type, break it down into
|
|
|
|
/// two smaller values, still of vector type.
|
2008-07-27 21:46:04 +00:00
|
|
|
void SelectionDAGLegalize::SplitVectorOp(SDValue Op, SDValue &Lo,
|
|
|
|
SDValue &Hi) {
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(Op.getValueType().isVector() && "Cannot split non-vector type!");
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-02 20:41:04 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned NumElements = Op.getValueType().getVectorNumElements();
|
2006-03-18 01:44:44 +00:00
|
|
|
assert(NumElements > 1 && "Cannot split a single element vector!");
|
2007-11-15 21:15:26 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewEltVT = Op.getValueType().getVectorElementType();
|
2007-11-15 21:15:26 +00:00
|
|
|
|
|
|
|
unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1);
|
|
|
|
unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo;
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewVT_Lo = MVT::getVectorVT(NewEltVT, NewNumElts_Lo);
|
|
|
|
MVT NewVT_Hi = MVT::getVectorVT(NewEltVT, NewNumElts_Hi);
|
2007-11-15 21:15:26 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// See if we already split it.
|
2008-07-27 21:46:04 +00:00
|
|
|
std::map<SDValue, std::pair<SDValue, SDValue> >::iterator I
|
2006-03-18 01:44:44 +00:00
|
|
|
= SplitNodes.find(Op);
|
|
|
|
if (I != SplitNodes.end()) {
|
|
|
|
Lo = I->second.first;
|
|
|
|
Hi = I->second.second;
|
|
|
|
return;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2009-02-17 22:15:04 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
Node->dump(&DAG);
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
|
|
|
assert(0 && "Unhandled operation in SplitVectorOp!");
|
2007-11-19 20:21:32 +00:00
|
|
|
case ISD::UNDEF:
|
2009-02-06 23:05:02 +00:00
|
|
|
Lo = DAG.getUNDEF(NewVT_Lo);
|
|
|
|
Hi = DAG.getUNDEF(NewVT_Hi);
|
2007-11-19 20:21:32 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_PAIR:
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
|
|
|
break;
|
2007-09-28 23:53:40 +00:00
|
|
|
case ISD::INSERT_VECTOR_ELT: {
|
2008-04-25 18:07:40 +00:00
|
|
|
if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) {
|
|
|
|
SplitVectorOp(Node->getOperand(0), Lo, Hi);
|
2008-09-12 16:56:44 +00:00
|
|
|
unsigned Index = Idx->getZExtValue();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ScalarOp = Node->getOperand(1);
|
2008-04-25 18:07:40 +00:00
|
|
|
if (Index < NewNumElts_Lo)
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVT_Lo, Lo, ScalarOp,
|
2008-04-25 18:07:40 +00:00
|
|
|
DAG.getIntPtrConstant(Index));
|
|
|
|
else
|
2009-02-02 22:49:46 +00:00
|
|
|
Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, NewVT_Hi, Hi, ScalarOp,
|
2008-04-25 18:07:40 +00:00
|
|
|
DAG.getIntPtrConstant(Index - NewNumElts_Lo));
|
|
|
|
break;
|
|
|
|
}
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0),
|
2009-04-10 18:48:47 +00:00
|
|
|
Node->getOperand(1),
|
|
|
|
Node->getOperand(2), dl);
|
2008-04-25 18:07:40 +00:00
|
|
|
SplitVectorOp(Tmp, Lo, Hi);
|
2007-09-28 23:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-19 21:16:54 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
|
|
|
// Build the low part.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Mask = Node->getOperand(2);
|
|
|
|
SmallVector<SDValue, 8> Ops;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = TLI.getPointerTy();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
|
|
|
// Insert all of the elements from the input that are needed. We use
|
2007-11-19 21:16:54 +00:00
|
|
|
// buildvector of extractelement here because the input vectors will have
|
|
|
|
// to be legalized, so this makes the code simpler.
|
|
|
|
for (unsigned i = 0; i != NewNumElts_Lo; ++i) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue IdxNode = Mask.getOperand(i);
|
2008-03-14 00:53:31 +00:00
|
|
|
if (IdxNode.getOpcode() == ISD::UNDEF) {
|
2009-02-06 23:05:02 +00:00
|
|
|
Ops.push_back(DAG.getUNDEF(NewEltVT));
|
2008-03-14 00:53:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-12 16:56:44 +00:00
|
|
|
unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InVec = Node->getOperand(0);
|
2007-11-19 21:16:54 +00:00
|
|
|
if (Idx >= NumElements) {
|
|
|
|
InVec = Node->getOperand(1);
|
|
|
|
Idx -= NumElements;
|
|
|
|
}
|
2009-02-02 22:49:46 +00:00
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewEltVT, InVec,
|
2007-11-19 21:16:54 +00:00
|
|
|
DAG.getConstant(Idx, PtrVT)));
|
|
|
|
}
|
2009-02-25 22:49:59 +00:00
|
|
|
Lo = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Lo, &Ops[0], Ops.size());
|
2007-11-19 21:16:54 +00:00
|
|
|
Ops.clear();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-11-19 21:16:54 +00:00
|
|
|
for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue IdxNode = Mask.getOperand(i);
|
2008-03-14 00:53:31 +00:00
|
|
|
if (IdxNode.getOpcode() == ISD::UNDEF) {
|
2009-02-06 23:05:02 +00:00
|
|
|
Ops.push_back(DAG.getUNDEF(NewEltVT));
|
2008-03-14 00:53:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-12 16:56:44 +00:00
|
|
|
unsigned Idx = cast<ConstantSDNode>(IdxNode)->getZExtValue();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InVec = Node->getOperand(0);
|
2007-11-19 21:16:54 +00:00
|
|
|
if (Idx >= NumElements) {
|
|
|
|
InVec = Node->getOperand(1);
|
|
|
|
Idx -= NumElements;
|
|
|
|
}
|
2009-02-02 22:49:46 +00:00
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewEltVT, InVec,
|
2007-11-19 21:16:54 +00:00
|
|
|
DAG.getConstant(Idx, PtrVT)));
|
|
|
|
}
|
2009-02-25 22:49:59 +00:00
|
|
|
Hi = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Hi, &Ops[0], Ops.size());
|
2007-11-19 21:16:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_VECTOR: {
|
2009-02-17 22:15:04 +00:00
|
|
|
SmallVector<SDValue, 8> LoOps(Node->op_begin(),
|
2009-04-10 18:48:47 +00:00
|
|
|
Node->op_begin()+NewNumElts_Lo);
|
2009-02-25 22:49:59 +00:00
|
|
|
Lo = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Lo, &LoOps[0], LoOps.size());
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumElts_Lo,
|
2009-04-10 18:48:47 +00:00
|
|
|
Node->op_end());
|
2009-02-25 22:49:59 +00:00
|
|
|
Hi = DAG.getNode(ISD::BUILD_VECTOR, dl, NewVT_Hi, &HiOps[0], HiOps.size());
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::CONCAT_VECTORS: {
|
2007-11-15 21:15:26 +00:00
|
|
|
// FIXME: Handle non-power-of-two vectors?
|
2007-06-25 16:23:39 +00:00
|
|
|
unsigned NewNumSubvectors = Node->getNumOperands() / 2;
|
|
|
|
if (NewNumSubvectors == 1) {
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
|
|
|
} else {
|
2008-11-10 04:46:22 +00:00
|
|
|
SmallVector<SDValue, 8> LoOps(Node->op_begin(),
|
|
|
|
Node->op_begin()+NewNumSubvectors);
|
2009-02-17 22:15:04 +00:00
|
|
|
Lo = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Lo,
|
2009-02-02 22:49:46 +00:00
|
|
|
&LoOps[0], LoOps.size());
|
2007-06-13 15:12:02 +00:00
|
|
|
|
2008-11-10 04:46:22 +00:00
|
|
|
SmallVector<SDValue, 8> HiOps(Node->op_begin()+NewNumSubvectors,
|
2009-04-10 18:48:47 +00:00
|
|
|
Node->op_end());
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = DAG.getNode(ISD::CONCAT_VECTORS, dl, NewVT_Hi,
|
2009-02-02 22:49:46 +00:00
|
|
|
&HiOps[0], HiOps.size());
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-10 04:46:22 +00:00
|
|
|
case ISD::EXTRACT_SUBVECTOR: {
|
|
|
|
SDValue Vec = Op.getOperand(0);
|
|
|
|
SDValue Idx = Op.getOperand(1);
|
|
|
|
MVT IdxVT = Idx.getValueType();
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Lo, Vec, Idx);
|
2008-11-10 04:46:22 +00:00
|
|
|
ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx);
|
|
|
|
if (CIdx) {
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Hi, Vec,
|
2008-11-10 04:46:22 +00:00
|
|
|
DAG.getConstant(CIdx->getZExtValue() + NewNumElts_Lo,
|
|
|
|
IdxVT));
|
|
|
|
} else {
|
2009-02-02 22:49:46 +00:00
|
|
|
Idx = DAG.getNode(ISD::ADD, dl, IdxVT, Idx,
|
2008-11-10 04:46:22 +00:00
|
|
|
DAG.getConstant(NewNumElts_Lo, IdxVT));
|
2009-02-02 22:49:46 +00:00
|
|
|
Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NewVT_Hi, Vec, Idx);
|
2008-11-10 04:46:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-17 14:48:28 +00:00
|
|
|
case ISD::SELECT: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Cond = Node->getOperand(0);
|
2007-10-17 14:48:28 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2007-10-17 14:48:28 +00:00
|
|
|
SplitVectorOp(Node->getOperand(1), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(2), RL, RH);
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
if (Cond.getValueType().isVector()) {
|
2007-10-17 14:48:28 +00:00
|
|
|
// Handle a vector merge.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CL, CH;
|
2007-10-17 14:48:28 +00:00
|
|
|
SplitVectorOp(Cond, CL, CH);
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, CL, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, CH, LH, RH);
|
2007-10-17 14:48:28 +00:00
|
|
|
} else {
|
|
|
|
// Handle a simple select with vector operands.
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, Cond, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, Cond, LH, RH);
|
2007-10-17 14:48:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-06-30 02:43:01 +00:00
|
|
|
case ISD::SELECT_CC: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CondLHS = Node->getOperand(0);
|
|
|
|
SDValue CondRHS = Node->getOperand(1);
|
|
|
|
SDValue CondCode = Node->getOperand(4);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2008-06-30 02:43:01 +00:00
|
|
|
SplitVectorOp(Node->getOperand(2), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(3), RL, RH);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-06-30 02:43:01 +00:00
|
|
|
// Handle a simple select with vector operands.
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT_CC, dl, NewVT_Lo, CondLHS, CondRHS,
|
2008-06-30 02:43:01 +00:00
|
|
|
LL, RL, CondCode);
|
2009-02-17 22:15:04 +00:00
|
|
|
Hi = DAG.getNode(ISD::SELECT_CC, dl, NewVT_Hi, CondLHS, CondRHS,
|
2008-06-30 02:43:01 +00:00
|
|
|
LH, RH, CondCode);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-12 19:40:03 +00:00
|
|
|
case ISD::VSETCC: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2008-05-12 19:40:03 +00:00
|
|
|
SplitVectorOp(Node->getOperand(0), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(1), RL, RH);
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(ISD::VSETCC, dl, NewVT_Lo, LL, RL, Node->getOperand(2));
|
|
|
|
Hi = DAG.getNode(ISD::VSETCC, dl, NewVT_Hi, LH, RH, Node->getOperand(2));
|
2008-05-12 19:40:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::FDIV:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
2007-11-19 15:15:03 +00:00
|
|
|
case ISD::XOR:
|
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::SREM:
|
2008-12-18 20:03:17 +00:00
|
|
|
case ISD::FREM:
|
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRA:
|
|
|
|
case ISD::SRL: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue LL, LH, RL, RH;
|
2006-03-18 01:44:44 +00:00
|
|
|
SplitVectorOp(Node->getOperand(0), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(1), RL, RH);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, LH, RH);
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-08-14 20:04:46 +00:00
|
|
|
case ISD::FP_ROUND:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOWI: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue L, H;
|
2007-10-11 23:57:53 +00:00
|
|
|
SplitVectorOp(Node->getOperand(0), L, H);
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, L, Node->getOperand(1));
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, H, Node->getOperand(1));
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::FNEG:
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
2007-11-17 03:58:34 +00:00
|
|
|
case ISD::FCOS:
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2007-11-17 03:58:34 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
case ISD::SINT_TO_FP:
|
2008-08-14 20:04:46 +00:00
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
case ISD::TRUNCATE:
|
|
|
|
case ISD::ANY_EXTEND:
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::FP_EXTEND: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue L, H;
|
2007-10-11 23:57:53 +00:00
|
|
|
SplitVectorOp(Node->getOperand(0), L, H);
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), dl, NewVT_Lo, L);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), dl, NewVT_Hi, H);
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CONVERT_RNDSAT: {
|
|
|
|
ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode();
|
|
|
|
SDValue L, H;
|
|
|
|
SplitVectorOp(Node->getOperand(0), L, H);
|
2009-04-10 18:48:47 +00:00
|
|
|
SDValue DTyOpL = DAG.getValueType(NewVT_Lo);
|
|
|
|
SDValue DTyOpH = DAG.getValueType(NewVT_Hi);
|
|
|
|
SDValue STyOpL = DAG.getValueType(L.getValueType());
|
|
|
|
SDValue STyOpH = DAG.getValueType(H.getValueType());
|
2008-11-10 20:54:11 +00:00
|
|
|
|
|
|
|
SDValue RndOp = Node->getOperand(3);
|
|
|
|
SDValue SatOp = Node->getOperand(4);
|
|
|
|
|
2009-02-04 00:13:36 +00:00
|
|
|
Lo = DAG.getConvertRndSat(NewVT_Lo, dl, L, DTyOpL, STyOpL,
|
2008-11-10 20:54:11 +00:00
|
|
|
RndOp, SatOp, CvtCode);
|
2009-02-04 00:13:36 +00:00
|
|
|
Hi = DAG.getConvertRndSat(NewVT_Hi, dl, H, DTyOpH, STyOpH,
|
2008-11-10 20:54:11 +00:00
|
|
|
RndOp, SatOp, CvtCode);
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ch = LD->getChain();
|
|
|
|
SDValue Ptr = LD->getBasePtr();
|
2008-08-14 20:04:46 +00:00
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
2007-06-25 16:23:39 +00:00
|
|
|
const Value *SV = LD->getSrcValue();
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
2008-08-14 20:04:46 +00:00
|
|
|
MVT MemoryVT = LD->getMemoryVT();
|
2007-06-25 16:23:39 +00:00
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
|
2008-08-14 20:04:46 +00:00
|
|
|
assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!");
|
2009-02-06 23:05:02 +00:00
|
|
|
SDValue Offset = DAG.getUNDEF(Ptr.getValueType());
|
2008-08-14 20:04:46 +00:00
|
|
|
|
|
|
|
MVT MemNewEltVT = MemoryVT.getVectorElementType();
|
|
|
|
MVT MemNewVT_Lo = MVT::getVectorVT(MemNewEltVT, NewNumElts_Lo);
|
|
|
|
MVT MemNewVT_Hi = MVT::getVectorVT(MemNewEltVT, NewNumElts_Hi);
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getLoad(ISD::UNINDEXED, dl, ExtType,
|
2008-08-14 20:04:46 +00:00
|
|
|
NewVT_Lo, Ch, Ptr, Offset,
|
|
|
|
SV, SVOffset, MemNewVT_Lo, isVolatile, Alignment);
|
|
|
|
unsigned IncrementSize = NewNumElts_Lo * MemNewEltVT.getSizeInBits()/8;
|
2009-02-02 22:49:46 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2007-06-25 16:23:39 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2009-02-02 22:49:46 +00:00
|
|
|
Hi = DAG.getLoad(ISD::UNINDEXED, dl, ExtType,
|
2008-08-14 20:04:46 +00:00
|
|
|
NewVT_Hi, Ch, Ptr, Offset,
|
|
|
|
SV, SVOffset, MemNewVT_Hi, isVolatile, Alignment);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Lo.getValue(1),
|
2009-04-10 18:48:47 +00:00
|
|
|
Hi.getValue(1));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF));
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BIT_CONVERT: {
|
2006-03-23 21:16:34 +00:00
|
|
|
// We know the result is a vector. The input may be either a vector or a
|
|
|
|
// scalar value.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InOp = Node->getOperand(0);
|
2008-06-06 12:08:01 +00:00
|
|
|
if (!InOp.getValueType().isVector() ||
|
|
|
|
InOp.getValueType().getVectorNumElements() == 1) {
|
2007-06-29 00:09:08 +00:00
|
|
|
// The input is a scalar or single-element vector.
|
|
|
|
// Lower to a store/load so that it can be split.
|
|
|
|
// FIXME: this could be improved probably.
|
2009-04-10 18:48:47 +00:00
|
|
|
unsigned LdAlign = TLI.getTargetData()->
|
|
|
|
getPrefTypeAlignment(Op.getValueType().getTypeForMVT());
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ptr = DAG.CreateStackTemporary(InOp.getValueType(), LdAlign);
|
2008-08-28 21:40:38 +00:00
|
|
|
int FI = cast<FrameIndexSDNode>(Ptr.getNode())->getIndex();
|
2006-03-23 21:16:34 +00:00
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue St = DAG.getStore(DAG.getEntryNode(), dl,
|
2009-04-10 18:48:47 +00:00
|
|
|
InOp, Ptr,
|
|
|
|
PseudoSourceValue::getFixedStack(FI), 0);
|
2009-02-02 22:49:46 +00:00
|
|
|
InOp = DAG.getLoad(Op.getValueType(), dl, St, Ptr,
|
2008-07-11 22:44:52 +00:00
|
|
|
PseudoSourceValue::getFixedStack(FI), 0);
|
2006-03-23 21:16:34 +00:00
|
|
|
}
|
2007-06-29 00:09:08 +00:00
|
|
|
// Split the vector and convert each of the pieces now.
|
|
|
|
SplitVectorOp(InOp, Lo, Hi);
|
2009-02-02 22:49:46 +00:00
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, dl, NewVT_Lo, Lo);
|
|
|
|
Hi = DAG.getNode(ISD::BIT_CONVERT, dl, NewVT_Hi, Hi);
|
2007-06-29 00:09:08 +00:00
|
|
|
break;
|
2006-03-23 21:16:34 +00:00
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// Remember in a map if the values will be reused later.
|
2009-02-17 22:15:04 +00:00
|
|
|
bool isNew =
|
2006-03-18 01:44:44 +00:00
|
|
|
SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second;
|
2007-06-29 00:09:08 +00:00
|
|
|
assert(isNew && "Value already split?!?");
|
2008-11-24 07:09:49 +00:00
|
|
|
isNew = isNew;
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-27 14:06:22 +00:00
|
|
|
/// ScalarizeVectorOp - Given an operand of single-element vector type
|
|
|
|
/// (e.g. v1f32), convert it into the equivalent operation that returns a
|
|
|
|
/// scalar (e.g. f32) value.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SelectionDAGLegalize::ScalarizeVectorOp(SDValue Op) {
|
2008-06-06 12:08:01 +00:00
|
|
|
assert(Op.getValueType().isVector() && "Bad ScalarizeVectorOp invocation!");
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-02 22:49:46 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT NewVT = Op.getValueType().getVectorElementType();
|
|
|
|
assert(Op.getValueType().getVectorNumElements() == 1);
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// See if we already scalarized it.
|
2008-07-27 21:46:04 +00:00
|
|
|
std::map<SDValue, SDValue>::iterator I = ScalarizedNodes.find(Op);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (I != ScalarizedNodes.end()) return I->second;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Result;
|
2006-03-18 01:44:44 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2009-02-17 22:15:04 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2007-06-25 16:23:39 +00:00
|
|
|
assert(0 && "Unknown vector operation in ScalarizeVectorOp!");
|
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::FDIV:
|
|
|
|
case ISD::SREM:
|
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::FREM:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl,
|
2009-02-17 22:15:04 +00:00
|
|
|
NewVT,
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Node->getOperand(0)),
|
|
|
|
ScalarizeVectorOp(Node->getOperand(1)));
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::FNEG:
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
2008-09-04 00:47:13 +00:00
|
|
|
case ISD::FLOG:
|
|
|
|
case ISD::FLOG2:
|
|
|
|
case ISD::FLOG10:
|
|
|
|
case ISD::FEXP:
|
|
|
|
case ISD::FEXP2:
|
2008-08-14 20:04:46 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::ANY_EXTEND:
|
|
|
|
case ISD::TRUNCATE:
|
|
|
|
case ISD::FP_EXTEND:
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl,
|
2009-02-17 22:15:04 +00:00
|
|
|
NewVT,
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Node->getOperand(0)));
|
|
|
|
break;
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CONVERT_RNDSAT: {
|
|
|
|
SDValue Op0 = ScalarizeVectorOp(Node->getOperand(0));
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getConvertRndSat(NewVT, dl, Op0,
|
2008-11-10 20:54:11 +00:00
|
|
|
DAG.getValueType(NewVT),
|
|
|
|
DAG.getValueType(Op0.getValueType()),
|
|
|
|
Node->getOperand(3),
|
|
|
|
Node->getOperand(4),
|
|
|
|
cast<CvtRndSatSDNode>(Node)->getCvtCode());
|
|
|
|
break;
|
|
|
|
}
|
2007-10-12 14:13:46 +00:00
|
|
|
case ISD::FPOWI:
|
2008-08-14 20:04:46 +00:00
|
|
|
case ISD::FP_ROUND:
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl,
|
2009-02-17 22:15:04 +00:00
|
|
|
NewVT,
|
2007-10-12 14:13:46 +00:00
|
|
|
ScalarizeVectorOp(Node->getOperand(0)),
|
|
|
|
Node->getOperand(1));
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ch = LegalizeOp(LD->getChain()); // Legalize the chain.
|
|
|
|
SDValue Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer.
|
2008-08-14 20:04:46 +00:00
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
2007-06-25 16:23:39 +00:00
|
|
|
const Value *SV = LD->getSrcValue();
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
2008-08-14 20:04:46 +00:00
|
|
|
MVT MemoryVT = LD->getMemoryVT();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
|
|
|
|
assert(LD->isUnindexed() && "Indexed vector loads are not supported yet!");
|
2009-02-06 23:05:02 +00:00
|
|
|
SDValue Offset = DAG.getUNDEF(Ptr.getValueType());
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getLoad(ISD::UNINDEXED, dl, ExtType,
|
2008-08-14 20:04:46 +00:00
|
|
|
NewVT, Ch, Ptr, Offset, SV, SVOffset,
|
|
|
|
MemoryVT.getVectorElementType(),
|
|
|
|
isVolatile, Alignment);
|
2007-06-25 16:23:39 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_VECTOR:
|
|
|
|
Result = Node->getOperand(0);
|
|
|
|
break;
|
|
|
|
case ISD::INSERT_VECTOR_ELT:
|
|
|
|
// Returning the inserted scalar element.
|
|
|
|
Result = Node->getOperand(1);
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::CONCAT_VECTORS:
|
2007-06-13 15:12:02 +00:00
|
|
|
assert(Node->getOperand(0).getValueType() == NewVT &&
|
|
|
|
"Concat of non-legal vectors not yet supported!");
|
|
|
|
Result = Node->getOperand(0);
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
|
|
|
// Figure out if the scalar is the LHS or RHS and return it.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue EltNum = Node->getOperand(2).getOperand(0);
|
2008-09-12 16:56:44 +00:00
|
|
|
if (cast<ConstantSDNode>(EltNum)->getZExtValue())
|
2007-06-25 16:23:39 +00:00
|
|
|
Result = ScalarizeVectorOp(Node->getOperand(1));
|
|
|
|
else
|
|
|
|
Result = ScalarizeVectorOp(Node->getOperand(0));
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, NewVT,
|
2009-02-02 22:49:46 +00:00
|
|
|
Node->getOperand(0), Node->getOperand(1));
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
2008-05-16 17:19:05 +00:00
|
|
|
case ISD::BIT_CONVERT: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op0 = Op.getOperand(0);
|
2008-06-06 12:08:01 +00:00
|
|
|
if (Op0.getValueType().getVectorNumElements() == 1)
|
2008-05-16 17:19:05 +00:00
|
|
|
Op0 = ScalarizeVectorOp(Op0);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, NewVT, Op0);
|
2006-04-10 18:54:36 +00:00
|
|
|
break;
|
2008-05-16 17:19:05 +00:00
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::SELECT:
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NewVT, Op.getOperand(0),
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Op.getOperand(1)),
|
|
|
|
ScalarizeVectorOp(Op.getOperand(2)));
|
2006-04-08 22:22:57 +00:00
|
|
|
break;
|
2008-06-30 02:43:01 +00:00
|
|
|
case ISD::SELECT_CC:
|
2009-02-17 22:15:04 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, dl, NewVT, Node->getOperand(0),
|
2008-06-30 02:43:01 +00:00
|
|
|
Node->getOperand(1),
|
|
|
|
ScalarizeVectorOp(Op.getOperand(2)),
|
|
|
|
ScalarizeVectorOp(Op.getOperand(3)),
|
|
|
|
Node->getOperand(4));
|
|
|
|
break;
|
2008-05-12 23:09:43 +00:00
|
|
|
case ISD::VSETCC: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op0 = ScalarizeVectorOp(Op.getOperand(0));
|
|
|
|
SDValue Op1 = ScalarizeVectorOp(Op.getOperand(1));
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::SETCC, dl,
|
|
|
|
TLI.getSetCCResultType(Op0.getValueType()),
|
2009-01-01 15:52:00 +00:00
|
|
|
Op0, Op1, Op.getOperand(2));
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, dl, NewVT, Result,
|
2008-05-12 23:09:43 +00:00
|
|
|
DAG.getConstant(-1ULL, NewVT),
|
|
|
|
DAG.getConstant(0ULL, NewVT));
|
|
|
|
break;
|
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TLI.isTypeLegal(NewVT))
|
|
|
|
Result = LegalizeOp(Result);
|
2007-06-25 16:23:39 +00:00
|
|
|
bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second;
|
|
|
|
assert(isNew && "Value already scalarized?");
|
2008-11-24 07:09:49 +00:00
|
|
|
isNew = isNew;
|
2006-03-18 01:44:44 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
SDValue SelectionDAGLegalize::WidenVectorOp(SDValue Op, MVT WidenVT) {
|
|
|
|
std::map<SDValue, SDValue>::iterator I = WidenNodes.find(Op);
|
|
|
|
if (I != WidenNodes.end()) return I->second;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
assert(VT.isVector() && "Cannot widen non-vector type!");
|
|
|
|
|
|
|
|
SDValue Result;
|
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-02 22:49:46 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2008-10-30 08:01:45 +00:00
|
|
|
MVT EVT = VT.getVectorElementType();
|
|
|
|
|
|
|
|
unsigned NumElts = VT.getVectorNumElements();
|
|
|
|
unsigned NewNumElts = WidenVT.getVectorNumElements();
|
|
|
|
assert(NewNumElts > NumElts && "Cannot widen to smaller type!");
|
|
|
|
assert(NewNumElts < 17);
|
|
|
|
|
|
|
|
// When widen is called, it is assumed that it is more efficient to use a
|
|
|
|
// wide type. The default action is to widen to operation to a wider legal
|
|
|
|
// vector type and then do the operation if it is legal by calling LegalizeOp
|
|
|
|
// again. If there is no vector equivalent, we will unroll the operation, do
|
|
|
|
// it, and rebuild the vector. If most of the operations are vectorizible to
|
|
|
|
// the legal type, the resulting code will be more efficient. If this is not
|
|
|
|
// the case, the resulting code will preform badly as we end up generating
|
|
|
|
// code to pack/unpack the results. It is the function that calls widen
|
2008-11-06 05:31:54 +00:00
|
|
|
// that is responsible for seeing this doesn't happen.
|
2008-10-30 08:01:45 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2009-02-17 22:15:04 +00:00
|
|
|
default:
|
2008-10-30 08:01:45 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
Node->dump(&DAG);
|
|
|
|
#endif
|
|
|
|
assert(0 && "Unexpected operation in WidenVectorOp!");
|
|
|
|
break;
|
|
|
|
case ISD::CopyFromReg:
|
2008-11-15 06:05:52 +00:00
|
|
|
assert(0 && "CopyFromReg doesn't need widening!");
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::Constant:
|
|
|
|
case ISD::ConstantFP:
|
|
|
|
// To build a vector of these elements, clients should call BuildVector
|
|
|
|
// and with each element instead of creating a node with a vector type
|
|
|
|
assert(0 && "Unexpected operation in WidenVectorOp!");
|
|
|
|
case ISD::VAARG:
|
|
|
|
// Variable Arguments with vector types doesn't make any sense to me
|
|
|
|
assert(0 && "Unexpected operation in WidenVectorOp!");
|
|
|
|
break;
|
2008-11-15 06:05:52 +00:00
|
|
|
case ISD::UNDEF:
|
2009-02-06 23:05:02 +00:00
|
|
|
Result = DAG.getUNDEF(WidenVT);
|
2008-11-15 06:05:52 +00:00
|
|
|
break;
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::BUILD_VECTOR: {
|
|
|
|
// Build a vector with undefined for the new nodes
|
|
|
|
SDValueVector NewOps(Node->op_begin(), Node->op_end());
|
|
|
|
for (unsigned i = NumElts; i < NewNumElts; ++i) {
|
2009-02-06 23:05:02 +00:00
|
|
|
NewOps.push_back(DAG.getUNDEF(EVT));
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
2009-02-25 22:49:59 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_VECTOR, dl, WidenVT,
|
|
|
|
&NewOps[0], NewOps.size());
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::INSERT_VECTOR_ELT: {
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, WidenVT, Tmp1,
|
2008-10-30 08:01:45 +00:00
|
|
|
Node->getOperand(1), Node->getOperand(2));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
|
|
|
SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT);
|
2009-04-27 18:41:29 +00:00
|
|
|
ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(Node);
|
|
|
|
SmallVector<int, 8> NewMask;
|
2008-10-30 08:01:45 +00:00
|
|
|
for (unsigned i = 0; i < NumElts; ++i) {
|
2009-04-27 18:41:29 +00:00
|
|
|
int Idx = SVOp->getMaskElt(i);
|
|
|
|
if (Idx < (int)NumElts)
|
|
|
|
NewMask.push_back(Idx);
|
|
|
|
else
|
|
|
|
NewMask.push_back(Idx + NewNumElts - NumElts);
|
2009-04-24 12:40:33 +00:00
|
|
|
}
|
2009-04-27 18:41:29 +00:00
|
|
|
for (unsigned i = NumElts; i < NewNumElts; ++i)
|
|
|
|
NewMask.push_back(-1);
|
|
|
|
|
|
|
|
Result = DAG.getVectorShuffle(WidenVT, dl, Tmp1, Tmp2, &NewMask[0]);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::LOAD: {
|
|
|
|
// If the load widen returns true, we can use a single load for the
|
|
|
|
// vector. Otherwise, it is returning a token factor for multiple
|
|
|
|
// loads.
|
|
|
|
SDValue TFOp;
|
|
|
|
if (LoadWidenVectorOp(Result, TFOp, Op, WidenVT))
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(1)));
|
|
|
|
else
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TFOp.getValue(0)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::BIT_CONVERT: {
|
|
|
|
SDValue Tmp1 = Node->getOperand(0);
|
|
|
|
// Converts between two different types so we need to determine
|
|
|
|
// the correct widen type for the input operand.
|
2008-12-18 20:03:17 +00:00
|
|
|
MVT InVT = Tmp1.getValueType();
|
2009-02-17 22:15:04 +00:00
|
|
|
unsigned WidenSize = WidenVT.getSizeInBits();
|
2008-12-18 20:03:17 +00:00
|
|
|
if (InVT.isVector()) {
|
|
|
|
MVT InEltVT = InVT.getVectorElementType();
|
|
|
|
unsigned InEltSize = InEltVT.getSizeInBits();
|
|
|
|
assert(WidenSize % InEltSize == 0 &&
|
|
|
|
"can not widen bit convert that are not multiple of element type");
|
|
|
|
MVT NewInWidenVT = MVT::getVectorVT(InEltVT, WidenSize / InEltSize);
|
|
|
|
Tmp1 = WidenVectorOp(Tmp1, NewInWidenVT);
|
|
|
|
assert(Tmp1.getValueType().getSizeInBits() == WidenVT.getSizeInBits());
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, WidenVT, Tmp1);
|
2008-12-18 20:03:17 +00:00
|
|
|
} else {
|
|
|
|
// If the result size is a multiple of the input size, widen the input
|
|
|
|
// and then convert.
|
|
|
|
unsigned InSize = InVT.getSizeInBits();
|
|
|
|
assert(WidenSize % InSize == 0 &&
|
|
|
|
"can not widen bit convert that are not multiple of element type");
|
|
|
|
unsigned NewNumElts = WidenSize / InSize;
|
|
|
|
SmallVector<SDValue, 16> Ops(NewNumElts);
|
2009-02-06 23:05:02 +00:00
|
|
|
SDValue UndefVal = DAG.getUNDEF(InVT);
|
2008-12-18 20:03:17 +00:00
|
|
|
Ops[0] = Tmp1;
|
|
|
|
for (unsigned i = 1; i < NewNumElts; ++i)
|
|
|
|
Ops[i] = UndefVal;
|
2008-10-30 08:01:45 +00:00
|
|
|
|
2008-12-18 20:03:17 +00:00
|
|
|
MVT NewInVT = MVT::getVectorVT(InVT, NewNumElts);
|
2009-02-25 22:49:59 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_VECTOR, dl, NewInVT, &Ops[0], NewNumElts);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, dl, WidenVT, Result);
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
case ISD::FP_TO_SINT:
|
2008-12-18 20:03:17 +00:00
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
case ISD::FP_ROUND: {
|
2008-10-30 08:01:45 +00:00
|
|
|
SDValue Tmp1 = Node->getOperand(0);
|
|
|
|
// Converts between two different types so we need to determine
|
|
|
|
// the correct widen type for the input operand.
|
|
|
|
MVT TVT = Tmp1.getValueType();
|
|
|
|
assert(TVT.isVector() && "can not widen non vector type");
|
|
|
|
MVT TEVT = TVT.getVectorElementType();
|
|
|
|
MVT TWidenVT = MVT::getVectorVT(TEVT, NewNumElts);
|
|
|
|
Tmp1 = WidenVectorOp(Tmp1, TWidenVT);
|
|
|
|
assert(Tmp1.getValueType().getVectorNumElements() == NewNumElts);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Tmp1);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::FP_EXTEND:
|
|
|
|
assert(0 && "Case not implemented. Dynamically dead with 2 FP types!");
|
|
|
|
case ISD::TRUNCATE:
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::ANY_EXTEND:
|
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FNEG:
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
2008-11-15 06:05:52 +00:00
|
|
|
case ISD::FCOS:
|
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ: {
|
2008-10-30 08:01:45 +00:00
|
|
|
// Unary op widening
|
2008-12-18 20:03:17 +00:00
|
|
|
SDValue Tmp1;
|
2008-10-30 08:01:45 +00:00
|
|
|
Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Tmp1);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-10 20:54:11 +00:00
|
|
|
case ISD::CONVERT_RNDSAT: {
|
|
|
|
SDValue RndOp = Node->getOperand(3);
|
|
|
|
SDValue SatOp = Node->getOperand(4);
|
|
|
|
SDValue SrcOp = Node->getOperand(0);
|
|
|
|
|
|
|
|
// Converts between two different types so we need to determine
|
|
|
|
// the correct widen type for the input operand.
|
|
|
|
MVT SVT = SrcOp.getValueType();
|
|
|
|
assert(SVT.isVector() && "can not widen non vector type");
|
|
|
|
MVT SEVT = SVT.getVectorElementType();
|
|
|
|
MVT SWidenVT = MVT::getVectorVT(SEVT, NewNumElts);
|
|
|
|
|
|
|
|
SrcOp = WidenVectorOp(SrcOp, SWidenVT);
|
|
|
|
assert(SrcOp.getValueType() == WidenVT);
|
|
|
|
SDValue DTyOp = DAG.getValueType(WidenVT);
|
|
|
|
SDValue STyOp = DAG.getValueType(SrcOp.getValueType());
|
|
|
|
ISD::CvtCode CvtCode = cast<CvtRndSatSDNode>(Node)->getCvtCode();
|
|
|
|
|
2009-02-04 00:13:36 +00:00
|
|
|
Result = DAG.getConvertRndSat(WidenVT, dl, SrcOp, DTyOp, STyOp,
|
2008-11-10 20:54:11 +00:00
|
|
|
RndOp, SatOp, CvtCode);
|
|
|
|
break;
|
|
|
|
}
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::FPOW:
|
2009-02-17 22:15:04 +00:00
|
|
|
case ISD::FPOWI:
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
case ISD::MULHS:
|
|
|
|
case ISD::MULHU:
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::SREM:
|
|
|
|
case ISD::FDIV:
|
|
|
|
case ISD::FREM:
|
|
|
|
case ISD::FCOPYSIGN:
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::BSWAP: {
|
|
|
|
// Binary op widening
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
|
|
|
SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Tmp1, Tmp2);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRA:
|
|
|
|
case ISD::SRL: {
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT);
|
2008-12-02 07:35:08 +00:00
|
|
|
SDValue ShOp = Node->getOperand(1);
|
|
|
|
MVT ShVT = ShOp.getValueType();
|
|
|
|
MVT NewShVT = MVT::getVectorVT(ShVT.getVectorElementType(),
|
|
|
|
WidenVT.getVectorNumElements());
|
|
|
|
ShOp = WidenVectorOp(ShOp, NewShVT);
|
|
|
|
assert(ShOp.getValueType() == NewShVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Tmp1, ShOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-02 07:35:08 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT: {
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(0), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, EVT, Tmp1, Node->getOperand(1));
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::CONCAT_VECTORS: {
|
|
|
|
// We concurrently support only widen on a multiple of the incoming vector.
|
|
|
|
// We could widen on a multiple of the incoming operand if necessary.
|
|
|
|
unsigned NumConcat = NewNumElts / NumElts;
|
|
|
|
assert(NewNumElts % NumElts == 0 && "Can widen only a multiple of vector");
|
2009-02-06 23:05:02 +00:00
|
|
|
SDValue UndefVal = DAG.getUNDEF(VT);
|
2008-10-30 08:01:45 +00:00
|
|
|
SmallVector<SDValue, 8> MOps;
|
|
|
|
MOps.push_back(Op);
|
|
|
|
for (unsigned i = 1; i != NumConcat; ++i) {
|
|
|
|
MOps.push_back(UndefVal);
|
|
|
|
}
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, dl, WidenVT,
|
2008-10-30 08:01:45 +00:00
|
|
|
&MOps[0], MOps.size()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::EXTRACT_SUBVECTOR: {
|
2008-11-15 06:05:52 +00:00
|
|
|
SDValue Tmp1 = Node->getOperand(0);
|
|
|
|
SDValue Idx = Node->getOperand(1);
|
|
|
|
ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx);
|
|
|
|
if (CIdx && CIdx->getZExtValue() == 0) {
|
|
|
|
// Since we are access the start of the vector, the incoming
|
|
|
|
// vector type might be the proper.
|
|
|
|
MVT Tmp1VT = Tmp1.getValueType();
|
|
|
|
if (Tmp1VT == WidenVT)
|
|
|
|
return Tmp1;
|
|
|
|
else {
|
|
|
|
unsigned Tmp1VTNumElts = Tmp1VT.getVectorNumElements();
|
|
|
|
if (Tmp1VTNumElts < NewNumElts)
|
|
|
|
Result = WidenVectorOp(Tmp1, WidenVT);
|
|
|
|
else
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, WidenVT, Tmp1, Idx);
|
2008-11-15 06:05:52 +00:00
|
|
|
}
|
|
|
|
} else if (NewNumElts % NumElts == 0) {
|
|
|
|
// Widen the extracted subvector.
|
|
|
|
unsigned NumConcat = NewNumElts / NumElts;
|
2009-02-06 23:05:02 +00:00
|
|
|
SDValue UndefVal = DAG.getUNDEF(VT);
|
2008-11-15 06:05:52 +00:00
|
|
|
SmallVector<SDValue, 8> MOps;
|
|
|
|
MOps.push_back(Op);
|
|
|
|
for (unsigned i = 1; i != NumConcat; ++i) {
|
|
|
|
MOps.push_back(UndefVal);
|
|
|
|
}
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = LegalizeOp(DAG.getNode(ISD::CONCAT_VECTORS, dl, WidenVT,
|
2008-11-15 06:05:52 +00:00
|
|
|
&MOps[0], MOps.size()));
|
|
|
|
} else {
|
|
|
|
assert(0 && "can not widen extract subvector");
|
|
|
|
// This could be implemented using insert and build vector but I would
|
|
|
|
// like to see when this happens.
|
|
|
|
}
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::SELECT: {
|
|
|
|
// Determine new condition widen type and widen
|
|
|
|
SDValue Cond1 = Node->getOperand(0);
|
|
|
|
MVT CondVT = Cond1.getValueType();
|
|
|
|
assert(CondVT.isVector() && "can not widen non vector type");
|
|
|
|
MVT CondEVT = CondVT.getVectorElementType();
|
|
|
|
MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts);
|
|
|
|
Cond1 = WidenVectorOp(Cond1, CondWidenVT);
|
|
|
|
assert(Cond1.getValueType() == CondWidenVT && "Condition not widen");
|
|
|
|
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(1), WidenVT);
|
|
|
|
SDValue Tmp2 = WidenVectorOp(Node->getOperand(2), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Cond1, Tmp1, Tmp2);
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
case ISD::SELECT_CC: {
|
|
|
|
// Determine new condition widen type and widen
|
|
|
|
SDValue Cond1 = Node->getOperand(0);
|
|
|
|
SDValue Cond2 = Node->getOperand(1);
|
|
|
|
MVT CondVT = Cond1.getValueType();
|
|
|
|
assert(CondVT.isVector() && "can not widen non vector type");
|
|
|
|
assert(CondVT == Cond2.getValueType() && "mismatch lhs/rhs");
|
|
|
|
MVT CondEVT = CondVT.getVectorElementType();
|
|
|
|
MVT CondWidenVT = MVT::getVectorVT(CondEVT, NewNumElts);
|
|
|
|
Cond1 = WidenVectorOp(Cond1, CondWidenVT);
|
|
|
|
Cond2 = WidenVectorOp(Cond2, CondWidenVT);
|
|
|
|
assert(Cond1.getValueType() == CondWidenVT &&
|
|
|
|
Cond2.getValueType() == CondWidenVT && "condition not widen");
|
|
|
|
|
|
|
|
SDValue Tmp1 = WidenVectorOp(Node->getOperand(2), WidenVT);
|
|
|
|
SDValue Tmp2 = WidenVectorOp(Node->getOperand(3), WidenVT);
|
|
|
|
assert(Tmp1.getValueType() == WidenVT && Tmp2.getValueType() == WidenVT &&
|
|
|
|
"operands not widen");
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Cond1, Cond2, Tmp1,
|
2008-10-30 08:01:45 +00:00
|
|
|
Tmp2, Node->getOperand(4));
|
|
|
|
break;
|
2008-10-30 18:21:52 +00:00
|
|
|
}
|
|
|
|
case ISD::VSETCC: {
|
|
|
|
// Determine widen for the operand
|
|
|
|
SDValue Tmp1 = Node->getOperand(0);
|
|
|
|
MVT TmpVT = Tmp1.getValueType();
|
|
|
|
assert(TmpVT.isVector() && "can not widen non vector type");
|
|
|
|
MVT TmpEVT = TmpVT.getVectorElementType();
|
|
|
|
MVT TmpWidenVT = MVT::getVectorVT(TmpEVT, NewNumElts);
|
|
|
|
Tmp1 = WidenVectorOp(Tmp1, TmpWidenVT);
|
|
|
|
SDValue Tmp2 = WidenVectorOp(Node->getOperand(1), TmpWidenVT);
|
2009-02-02 22:49:46 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), dl, WidenVT, Tmp1, Tmp2,
|
2008-10-30 18:21:52 +00:00
|
|
|
Node->getOperand(2));
|
2008-10-30 08:01:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-23 21:37:04 +00:00
|
|
|
case ISD::ATOMIC_CMP_SWAP:
|
|
|
|
case ISD::ATOMIC_LOAD_ADD:
|
|
|
|
case ISD::ATOMIC_LOAD_SUB:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_NAND:
|
|
|
|
case ISD::ATOMIC_LOAD_MIN:
|
|
|
|
case ISD::ATOMIC_LOAD_MAX:
|
|
|
|
case ISD::ATOMIC_LOAD_UMIN:
|
|
|
|
case ISD::ATOMIC_LOAD_UMAX:
|
|
|
|
case ISD::ATOMIC_SWAP: {
|
2008-10-30 08:01:45 +00:00
|
|
|
// For now, we assume that using vectors for these operations don't make
|
|
|
|
// much sense so we just split it. We return an empty result
|
|
|
|
SDValue X, Y;
|
|
|
|
SplitVectorOp(Op, X, Y);
|
|
|
|
return Result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end switch (Node->getOpcode())
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
assert(Result.getNode() && "Didn't set a result!");
|
2008-10-30 08:01:45 +00:00
|
|
|
if (Result != Op)
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
|
2008-11-06 05:31:54 +00:00
|
|
|
AddWidenedOperand(Op, Result);
|
2008-10-30 08:01:45 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Utility function to find a legal vector type and its associated element
|
|
|
|
// type from a preferred width and whose vector type must be the same size
|
|
|
|
// as the VVT.
|
|
|
|
// TLI: Target lowering used to determine legal types
|
|
|
|
// Width: Preferred width of element type
|
|
|
|
// VVT: Vector value type whose size we must match.
|
|
|
|
// Returns VecEVT and EVT - the vector type and its associated element type
|
2009-01-15 16:43:02 +00:00
|
|
|
static void FindWidenVecType(const TargetLowering &TLI, unsigned Width, MVT VVT,
|
2008-10-30 08:01:45 +00:00
|
|
|
MVT& EVT, MVT& VecEVT) {
|
|
|
|
// We start with the preferred width, make it a power of 2 and see if
|
|
|
|
// we can find a vector type of that width. If not, we reduce it by
|
|
|
|
// another power of 2. If we have widen the type, a vector of bytes should
|
|
|
|
// always be legal.
|
|
|
|
assert(TLI.isTypeLegal(VVT));
|
|
|
|
unsigned EWidth = Width + 1;
|
|
|
|
do {
|
|
|
|
assert(EWidth > 0);
|
|
|
|
EWidth = (1 << Log2_32(EWidth-1));
|
|
|
|
EVT = MVT::getIntegerVT(EWidth);
|
|
|
|
unsigned NumEVT = VVT.getSizeInBits()/EWidth;
|
|
|
|
VecEVT = MVT::getVectorVT(EVT, NumEVT);
|
|
|
|
} while (!TLI.isTypeLegal(VecEVT) ||
|
|
|
|
VVT.getSizeInBits() != VecEVT.getSizeInBits());
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue SelectionDAGLegalize::genWidenVectorLoads(SDValueVector& LdChain,
|
|
|
|
SDValue Chain,
|
|
|
|
SDValue BasePtr,
|
|
|
|
const Value *SV,
|
|
|
|
int SVOffset,
|
|
|
|
unsigned Alignment,
|
|
|
|
bool isVolatile,
|
|
|
|
unsigned LdWidth,
|
2009-02-02 22:49:46 +00:00
|
|
|
MVT ResType,
|
|
|
|
DebugLoc dl) {
|
2008-10-30 08:01:45 +00:00
|
|
|
// We assume that we have good rules to handle loading power of two loads so
|
|
|
|
// we break down the operations to power of 2 loads. The strategy is to
|
|
|
|
// load the largest power of 2 that we can easily transform to a legal vector
|
|
|
|
// and then insert into that vector, and the cast the result into the legal
|
|
|
|
// vector that we want. This avoids unnecessary stack converts.
|
|
|
|
// TODO: If the Ldwidth is legal, alignment is the same as the LdWidth, and
|
|
|
|
// the load is nonvolatile, we an use a wider load for the value.
|
|
|
|
// Find a vector length we can load a large chunk
|
|
|
|
MVT EVT, VecEVT;
|
|
|
|
unsigned EVTWidth;
|
|
|
|
FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT);
|
|
|
|
EVTWidth = EVT.getSizeInBits();
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue LdOp = DAG.getLoad(EVT, dl, Chain, BasePtr, SV, SVOffset,
|
2009-04-10 18:48:47 +00:00
|
|
|
isVolatile, Alignment);
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue VecOp = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VecEVT, LdOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
LdChain.push_back(LdOp.getValue(1));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
// Check if we can load the element with one instruction
|
|
|
|
if (LdWidth == EVTWidth) {
|
2009-02-02 22:49:46 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, ResType, VecOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The vector element order is endianness dependent.
|
|
|
|
unsigned Idx = 1;
|
|
|
|
LdWidth -= EVTWidth;
|
|
|
|
unsigned Offset = 0;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
while (LdWidth > 0) {
|
|
|
|
unsigned Increment = EVTWidth / 8;
|
|
|
|
Offset += Increment;
|
2009-02-02 22:49:46 +00:00
|
|
|
BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr,
|
2008-10-30 08:01:45 +00:00
|
|
|
DAG.getIntPtrConstant(Increment));
|
|
|
|
|
|
|
|
if (LdWidth < EVTWidth) {
|
|
|
|
// Our current type we are using is too large, use a smaller size by
|
|
|
|
// using a smaller power of 2
|
|
|
|
unsigned oEVTWidth = EVTWidth;
|
|
|
|
FindWidenVecType(TLI, LdWidth, ResType, EVT, VecEVT);
|
|
|
|
EVTWidth = EVT.getSizeInBits();
|
|
|
|
// Readjust position and vector position based on new load type
|
2008-11-15 06:05:52 +00:00
|
|
|
Idx = Idx * (oEVTWidth/EVTWidth);
|
2009-02-02 22:49:46 +00:00
|
|
|
VecOp = DAG.getNode(ISD::BIT_CONVERT, dl, VecEVT, VecOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue LdOp = DAG.getLoad(EVT, dl, Chain, BasePtr, SV,
|
2009-04-10 18:48:47 +00:00
|
|
|
SVOffset+Offset, isVolatile,
|
|
|
|
MinAlign(Alignment, Offset));
|
2008-10-30 08:01:45 +00:00
|
|
|
LdChain.push_back(LdOp.getValue(1));
|
2009-02-02 22:49:46 +00:00
|
|
|
VecOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecEVT, VecOp, LdOp,
|
2008-10-30 08:01:45 +00:00
|
|
|
DAG.getIntPtrConstant(Idx++));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
LdWidth -= EVTWidth;
|
|
|
|
}
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, ResType, VecOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SelectionDAGLegalize::LoadWidenVectorOp(SDValue& Result,
|
|
|
|
SDValue& TFOp,
|
|
|
|
SDValue Op,
|
|
|
|
MVT NVT) {
|
|
|
|
// TODO: Add support for ConcatVec and the ability to load many vector
|
|
|
|
// types (e.g., v4i8). This will not work when a vector register
|
|
|
|
// to memory mapping is strange (e.g., vector elements are not
|
|
|
|
// stored in some sequential order).
|
|
|
|
|
2009-02-17 22:15:04 +00:00
|
|
|
// It must be true that the widen vector type is bigger than where
|
2008-10-30 08:01:45 +00:00
|
|
|
// we need to load from.
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Op.getNode());
|
|
|
|
MVT LdVT = LD->getMemoryVT();
|
2009-02-02 22:49:46 +00:00
|
|
|
DebugLoc dl = LD->getDebugLoc();
|
2008-10-30 08:01:45 +00:00
|
|
|
assert(LdVT.isVector() && NVT.isVector());
|
|
|
|
assert(LdVT.getVectorElementType() == NVT.getVectorElementType());
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
// Load information
|
|
|
|
SDValue Chain = LD->getChain();
|
|
|
|
SDValue BasePtr = LD->getBasePtr();
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
const Value *SV = LD->getSrcValue();
|
|
|
|
unsigned int LdWidth = LdVT.getSizeInBits();
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
// Load value as a large register
|
|
|
|
SDValueVector LdChain;
|
|
|
|
Result = genWidenVectorLoads(LdChain, Chain, BasePtr, SV, SVOffset,
|
2009-02-02 22:49:46 +00:00
|
|
|
Alignment, isVolatile, LdWidth, NVT, dl);
|
2008-10-30 08:01:45 +00:00
|
|
|
|
|
|
|
if (LdChain.size() == 1) {
|
|
|
|
TFOp = LdChain[0];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2009-02-17 22:15:04 +00:00
|
|
|
TFOp=DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2009-02-02 22:49:46 +00:00
|
|
|
&LdChain[0], LdChain.size());
|
2008-10-30 08:01:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionDAGLegalize::genWidenVectorStores(SDValueVector& StChain,
|
|
|
|
SDValue Chain,
|
|
|
|
SDValue BasePtr,
|
|
|
|
const Value *SV,
|
|
|
|
int SVOffset,
|
|
|
|
unsigned Alignment,
|
|
|
|
bool isVolatile,
|
2008-11-15 06:05:52 +00:00
|
|
|
SDValue ValOp,
|
2009-02-02 22:49:46 +00:00
|
|
|
unsigned StWidth,
|
|
|
|
DebugLoc dl) {
|
2008-10-30 08:01:45 +00:00
|
|
|
// Breaks the stores into a series of power of 2 width stores. For any
|
|
|
|
// width, we convert the vector to the vector of element size that we
|
|
|
|
// want to store. This avoids requiring a stack convert.
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
// Find a width of the element type we can store with
|
|
|
|
MVT VVT = ValOp.getValueType();
|
|
|
|
MVT EVT, VecEVT;
|
|
|
|
unsigned EVTWidth;
|
|
|
|
FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT);
|
|
|
|
EVTWidth = EVT.getSizeInBits();
|
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue VecOp = DAG.getNode(ISD::BIT_CONVERT, dl, VecEVT, ValOp);
|
|
|
|
SDValue EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EVT, VecOp,
|
2008-11-06 22:52:21 +00:00
|
|
|
DAG.getIntPtrConstant(0));
|
2009-02-02 22:49:46 +00:00
|
|
|
SDValue StOp = DAG.getStore(Chain, dl, EOp, BasePtr, SV, SVOffset,
|
2009-04-10 18:48:47 +00:00
|
|
|
isVolatile, Alignment);
|
2008-10-30 08:01:45 +00:00
|
|
|
StChain.push_back(StOp);
|
|
|
|
|
|
|
|
// Check if we are done
|
|
|
|
if (StWidth == EVTWidth) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
unsigned Idx = 1;
|
|
|
|
StWidth -= EVTWidth;
|
|
|
|
unsigned Offset = 0;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
while (StWidth > 0) {
|
|
|
|
unsigned Increment = EVTWidth / 8;
|
|
|
|
Offset += Increment;
|
2009-02-02 22:49:46 +00:00
|
|
|
BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr,
|
2008-10-30 08:01:45 +00:00
|
|
|
DAG.getIntPtrConstant(Increment));
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
if (StWidth < EVTWidth) {
|
|
|
|
// Our current type we are using is too large, use a smaller size by
|
|
|
|
// using a smaller power of 2
|
|
|
|
unsigned oEVTWidth = EVTWidth;
|
|
|
|
FindWidenVecType(TLI, StWidth, VVT, EVT, VecEVT);
|
|
|
|
EVTWidth = EVT.getSizeInBits();
|
|
|
|
// Readjust position and vector position based on new load type
|
2008-11-15 06:05:52 +00:00
|
|
|
Idx = Idx * (oEVTWidth/EVTWidth);
|
2009-02-02 22:49:46 +00:00
|
|
|
VecOp = DAG.getNode(ISD::BIT_CONVERT, dl, VecEVT, VecOp);
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2009-02-02 22:49:46 +00:00
|
|
|
EOp = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EVT, VecOp,
|
2008-11-15 06:05:52 +00:00
|
|
|
DAG.getIntPtrConstant(Idx++));
|
2009-02-02 22:49:46 +00:00
|
|
|
StChain.push_back(DAG.getStore(Chain, dl, EOp, BasePtr, SV,
|
2008-10-30 08:01:45 +00:00
|
|
|
SVOffset + Offset, isVolatile,
|
|
|
|
MinAlign(Alignment, Offset)));
|
|
|
|
StWidth -= EVTWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SDValue SelectionDAGLegalize::StoreWidenVectorOp(StoreSDNode *ST,
|
2009-04-10 18:48:47 +00:00
|
|
|
SDValue Chain,
|
|
|
|
SDValue BasePtr) {
|
2008-10-30 08:01:45 +00:00
|
|
|
// TODO: It might be cleaner if we can use SplitVector and have more legal
|
|
|
|
// vector types that can be stored into memory (e.g., v4xi8 can
|
|
|
|
// be stored as a word). This will not work when a vector register
|
|
|
|
// to memory mapping is strange (e.g., vector elements are not
|
|
|
|
// stored in some sequential order).
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
MVT StVT = ST->getMemoryVT();
|
|
|
|
SDValue ValOp = ST->getValue();
|
2009-02-02 22:49:46 +00:00
|
|
|
DebugLoc dl = ST->getDebugLoc();
|
2008-10-30 08:01:45 +00:00
|
|
|
|
|
|
|
// Check if we have widen this node with another value
|
|
|
|
std::map<SDValue, SDValue>::iterator I = WidenNodes.find(ValOp);
|
|
|
|
if (I != WidenNodes.end())
|
|
|
|
ValOp = I->second;
|
2009-02-17 22:15:04 +00:00
|
|
|
|
2008-10-30 08:01:45 +00:00
|
|
|
MVT VVT = ValOp.getValueType();
|
|
|
|
|
|
|
|
// It must be true that we the widen vector type is bigger than where
|
|
|
|
// we need to store.
|
|
|
|
assert(StVT.isVector() && VVT.isVector());
|
2009-01-28 03:10:52 +00:00
|
|
|
assert(StVT.bitsLT(VVT));
|
2008-10-30 08:01:45 +00:00
|
|
|
assert(StVT.getVectorElementType() == VVT.getVectorElementType());
|
|
|
|
|
|
|
|
// Store value
|
|
|
|
SDValueVector StChain;
|
|
|
|
genWidenVectorStores(StChain, Chain, BasePtr, ST->getSrcValue(),
|
|
|
|
ST->getSrcValueOffset(), ST->getAlignment(),
|
2009-02-02 22:49:46 +00:00
|
|
|
ST->isVolatile(), ValOp, StVT.getSizeInBits(), dl);
|
2008-10-30 08:01:45 +00:00
|
|
|
if (StChain.size() == 1)
|
|
|
|
return StChain[0];
|
2009-02-17 22:15:04 +00:00
|
|
|
else
|
2009-02-02 22:49:46 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
|
|
|
&StChain[0], StChain.size());
|
2008-10-30 08:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// SelectionDAG::Legalize - This is the entry point for the file.
|
|
|
|
//
|
2009-04-29 23:29:43 +00:00
|
|
|
void SelectionDAG::Legalize(bool TypesNeedLegalizing,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2005-01-07 07:47:09 +00:00
|
|
|
/// run - This is the main entry point to this class.
|
|
|
|
///
|
2009-04-29 00:15:41 +00:00
|
|
|
SelectionDAGLegalize(*this, TypesNeedLegalizing, OptLevel).LegalizeDAG();
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|