mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-21 21:11:36 +00:00
[DAGCombiner] Update MatchRotate so that it returns an SDValue. NFC
llvm-svn: 373260
This commit is contained in:
parent
6057807666
commit
0f776528df
@ -540,11 +540,11 @@ namespace {
|
||||
SDValue MatchBSwapHWordLow(SDNode *N, SDValue N0, SDValue N1,
|
||||
bool DemandHighBits = true);
|
||||
SDValue MatchBSwapHWord(SDNode *N, SDValue N0, SDValue N1);
|
||||
SDNode *MatchRotatePosNeg(SDValue Shifted, SDValue Pos, SDValue Neg,
|
||||
SDValue MatchRotatePosNeg(SDValue Shifted, SDValue Pos, SDValue Neg,
|
||||
SDValue InnerPos, SDValue InnerNeg,
|
||||
unsigned PosOpcode, unsigned NegOpcode,
|
||||
const SDLoc &DL);
|
||||
SDNode *MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL);
|
||||
SDValue MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL);
|
||||
SDValue MatchLoadCombine(SDNode *N);
|
||||
SDValue MatchStoreCombine(StoreSDNode *N);
|
||||
SDValue ReduceLoadWidth(SDNode *N);
|
||||
@ -6062,8 +6062,8 @@ SDValue DAGCombiner::visitOR(SDNode *N) {
|
||||
return V;
|
||||
|
||||
// See if this is some rotate idiom.
|
||||
if (SDNode *Rot = MatchRotate(N0, N1, SDLoc(N)))
|
||||
return SDValue(Rot, 0);
|
||||
if (SDValue Rot = MatchRotate(N0, N1, SDLoc(N)))
|
||||
return Rot;
|
||||
|
||||
if (SDValue Load = MatchLoadCombine(N))
|
||||
return Load;
|
||||
@ -6348,7 +6348,7 @@ static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned EltSize,
|
||||
// to both (PosOpcode Shifted, Pos) and (NegOpcode Shifted, Neg), with the
|
||||
// former being preferred if supported. InnerPos and InnerNeg are Pos and
|
||||
// Neg with outer conversions stripped away.
|
||||
SDNode *DAGCombiner::MatchRotatePosNeg(SDValue Shifted, SDValue Pos,
|
||||
SDValue DAGCombiner::MatchRotatePosNeg(SDValue Shifted, SDValue Pos,
|
||||
SDValue Neg, SDValue InnerPos,
|
||||
SDValue InnerNeg, unsigned PosOpcode,
|
||||
unsigned NegOpcode, const SDLoc &DL) {
|
||||
@ -6363,32 +6363,31 @@ SDNode *DAGCombiner::MatchRotatePosNeg(SDValue Shifted, SDValue Pos,
|
||||
if (matchRotateSub(InnerPos, InnerNeg, VT.getScalarSizeInBits(), DAG)) {
|
||||
bool HasPos = TLI.isOperationLegalOrCustom(PosOpcode, VT);
|
||||
return DAG.getNode(HasPos ? PosOpcode : NegOpcode, DL, VT, Shifted,
|
||||
HasPos ? Pos : Neg).getNode();
|
||||
HasPos ? Pos : Neg);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return SDValue();
|
||||
}
|
||||
|
||||
// MatchRotate - Handle an 'or' of two operands. If this is one of the many
|
||||
// idioms for rotate, and if the target supports rotation instructions, generate
|
||||
// a rot[lr].
|
||||
SDNode *DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
SDValue DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
// Must be a legal type. Expanded 'n promoted things won't work with rotates.
|
||||
EVT VT = LHS.getValueType();
|
||||
if (!TLI.isTypeLegal(VT)) return nullptr;
|
||||
if (!TLI.isTypeLegal(VT)) return SDValue();
|
||||
|
||||
// The target must have at least one rotate flavor.
|
||||
bool HasROTL = hasOperation(ISD::ROTL, VT);
|
||||
bool HasROTR = hasOperation(ISD::ROTR, VT);
|
||||
if (!HasROTL && !HasROTR) return nullptr;
|
||||
if (!HasROTL && !HasROTR) return SDValue();
|
||||
|
||||
// Check for truncated rotate.
|
||||
if (LHS.getOpcode() == ISD::TRUNCATE && RHS.getOpcode() == ISD::TRUNCATE &&
|
||||
LHS.getOperand(0).getValueType() == RHS.getOperand(0).getValueType()) {
|
||||
assert(LHS.getValueType() == RHS.getValueType());
|
||||
if (SDNode *Rot = MatchRotate(LHS.getOperand(0), RHS.getOperand(0), DL)) {
|
||||
return DAG.getNode(ISD::TRUNCATE, SDLoc(LHS), LHS.getValueType(),
|
||||
SDValue(Rot, 0)).getNode();
|
||||
if (SDValue Rot = MatchRotate(LHS.getOperand(0), RHS.getOperand(0), DL)) {
|
||||
return DAG.getNode(ISD::TRUNCATE, SDLoc(LHS), LHS.getValueType(), Rot);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6403,7 +6402,7 @@ SDNode *DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
|
||||
// If neither side matched a rotate half, bail
|
||||
if (!LHSShift && !RHSShift)
|
||||
return nullptr;
|
||||
return SDValue();
|
||||
|
||||
// InstCombine may have combined a constant shl, srl, mul, or udiv with one
|
||||
// side of the rotate, so try to handle that here. In all cases we need to
|
||||
@ -6426,15 +6425,15 @@ SDNode *DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
|
||||
// If a side is still missing, nothing else we can do.
|
||||
if (!RHSShift || !LHSShift)
|
||||
return nullptr;
|
||||
return SDValue();
|
||||
|
||||
// At this point we've matched or extracted a shift op on each side.
|
||||
|
||||
if (LHSShift.getOperand(0) != RHSShift.getOperand(0))
|
||||
return nullptr; // Not shifting the same value.
|
||||
return SDValue(); // Not shifting the same value.
|
||||
|
||||
if (LHSShift.getOpcode() == RHSShift.getOpcode())
|
||||
return nullptr; // Shifts must disagree.
|
||||
return SDValue(); // Shifts must disagree.
|
||||
|
||||
// Canonicalize shl to left side in a shl/srl pair.
|
||||
if (RHSShift.getOpcode() == ISD::SHL) {
|
||||
@ -6478,13 +6477,13 @@ SDNode *DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
Rot = DAG.getNode(ISD::AND, DL, VT, Rot, Mask);
|
||||
}
|
||||
|
||||
return Rot.getNode();
|
||||
return Rot;
|
||||
}
|
||||
|
||||
// If there is a mask here, and we have a variable shift, we can't be sure
|
||||
// that we're masking out the right stuff.
|
||||
if (LHSMask.getNode() || RHSMask.getNode())
|
||||
return nullptr;
|
||||
return SDValue();
|
||||
|
||||
// If the shift amount is sign/zext/any-extended just peel it off.
|
||||
SDValue LExtOp0 = LHSShiftAmt;
|
||||
@ -6501,17 +6500,17 @@ SDNode *DAGCombiner::MatchRotate(SDValue LHS, SDValue RHS, const SDLoc &DL) {
|
||||
RExtOp0 = RHSShiftAmt.getOperand(0);
|
||||
}
|
||||
|
||||
SDNode *TryL = MatchRotatePosNeg(LHSShiftArg, LHSShiftAmt, RHSShiftAmt,
|
||||
SDValue TryL = MatchRotatePosNeg(LHSShiftArg, LHSShiftAmt, RHSShiftAmt,
|
||||
LExtOp0, RExtOp0, ISD::ROTL, ISD::ROTR, DL);
|
||||
if (TryL)
|
||||
return TryL;
|
||||
|
||||
SDNode *TryR = MatchRotatePosNeg(RHSShiftArg, RHSShiftAmt, LHSShiftAmt,
|
||||
SDValue TryR = MatchRotatePosNeg(RHSShiftArg, RHSShiftAmt, LHSShiftAmt,
|
||||
RExtOp0, LExtOp0, ISD::ROTR, ISD::ROTL, DL);
|
||||
if (TryR)
|
||||
return TryR;
|
||||
|
||||
return nullptr;
|
||||
return SDValue();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
Loading…
x
Reference in New Issue
Block a user