[DAG] visitShiftByConstant - replace constant detection with FoldConstantArithmetic
Instead of checking that an operand is constant/opaque before calling getNode() and then checking that the result is a constant, just use FoldConstantArithmetic which will just early-out if the operands are not constant foldable.
This commit is contained in:
parent
45cadb4bd3
commit
8e77458578
@ -8880,11 +8880,6 @@ SDValue DAGCombiner::visitShiftByConstant(SDNode *N) {
|
||||
break;
|
||||
}
|
||||
|
||||
// We require the RHS of the binop to be a constant and not opaque as well.
|
||||
ConstantSDNode *BinOpCst = getAsNonOpaqueConstant(LHS.getOperand(1));
|
||||
if (!BinOpCst)
|
||||
return SDValue();
|
||||
|
||||
// FIXME: disable this unless the input to the binop is a shift by a constant
|
||||
// or is copy/select. Enable this in other cases when figure out it's exactly
|
||||
// profitable.
|
||||
@ -8902,16 +8897,17 @@ SDValue DAGCombiner::visitShiftByConstant(SDNode *N) {
|
||||
if (IsCopyOrSelect && N->hasOneUse())
|
||||
return SDValue();
|
||||
|
||||
// Fold the constants, shifting the binop RHS by the shift amount.
|
||||
// Attempt to fold the constants, shifting the binop RHS by the shift amount.
|
||||
SDLoc DL(N);
|
||||
EVT VT = N->getValueType(0);
|
||||
SDValue NewRHS = DAG.getNode(N->getOpcode(), DL, VT, LHS.getOperand(1),
|
||||
N->getOperand(1));
|
||||
assert(isa<ConstantSDNode>(NewRHS) && "Folding was not successful!");
|
||||
if (SDValue NewRHS = DAG.FoldConstantArithmetic(
|
||||
N->getOpcode(), DL, VT, {LHS.getOperand(1), N->getOperand(1)})) {
|
||||
SDValue NewShift = DAG.getNode(N->getOpcode(), DL, VT, LHS.getOperand(0),
|
||||
N->getOperand(1));
|
||||
return DAG.getNode(LHS.getOpcode(), DL, VT, NewShift, NewRHS);
|
||||
}
|
||||
|
||||
SDValue NewShift = DAG.getNode(N->getOpcode(), DL, VT, LHS.getOperand(0),
|
||||
N->getOperand(1));
|
||||
return DAG.getNode(LHS.getOpcode(), DL, VT, NewShift, NewRHS);
|
||||
return SDValue();
|
||||
}
|
||||
|
||||
SDValue DAGCombiner::distributeTruncateThroughAnd(SDNode *N) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user