forked from OSchip/llvm-project
[DAGCombiner] visitIMINMAX - use general SelectionDAG::FoldConstantArithmetic
This handles all the constant splat / opaque testing for us instead of the ConstantSDNode variant where we have to do it ourselves.
This commit is contained in:
parent
e5edd641fd
commit
48bd6a0986
|
@ -4321,6 +4321,7 @@ SDValue DAGCombiner::visitIMINMAX(SDNode *N) {
|
|||
SDValue N0 = N->getOperand(0);
|
||||
SDValue N1 = N->getOperand(1);
|
||||
EVT VT = N0.getValueType();
|
||||
unsigned Opcode = N->getOpcode();
|
||||
|
||||
// fold vector ops
|
||||
if (VT.isVector())
|
||||
|
@ -4328,19 +4329,16 @@ SDValue DAGCombiner::visitIMINMAX(SDNode *N) {
|
|||
return FoldedVOp;
|
||||
|
||||
// fold operation with constant operands.
|
||||
ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
|
||||
ConstantSDNode *N1C = getAsNonOpaqueConstant(N1);
|
||||
if (N0C && N1C)
|
||||
return DAG.FoldConstantArithmetic(N->getOpcode(), SDLoc(N), VT, N0C, N1C);
|
||||
if (SDValue C = DAG.FoldConstantArithmetic(Opcode, SDLoc(N), VT, {N0, N1}))
|
||||
return C;
|
||||
|
||||
// canonicalize constant to RHS
|
||||
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
|
||||
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
|
||||
!DAG.isConstantIntBuildVectorOrConstantInt(N1))
|
||||
return DAG.getNode(N->getOpcode(), SDLoc(N), VT, N1, N0);
|
||||
|
||||
// Is sign bits are zero, flip between UMIN/UMAX and SMIN/SMAX.
|
||||
// Only do this if the current op isn't legal and the flipped is.
|
||||
unsigned Opcode = N->getOpcode();
|
||||
if (!TLI.isOperationLegal(Opcode, VT) &&
|
||||
(N0.isUndef() || DAG.SignBitIsZero(N0)) &&
|
||||
(N1.isUndef() || DAG.SignBitIsZero(N1))) {
|
||||
|
|
Loading…
Reference in New Issue