@@ -5453,7 +5453,7 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5453
5453
EVT ShSVT = ShVT.getScalarType ();
5454
5454
5455
5455
// If MUL is unavailable, we cannot proceed in any case.
5456
- if (!isOperationLegalOrCustom (ISD::MUL, VT))
5456
+ if (!DCI. isBeforeLegalizeOps () && ! isOperationLegalOrCustom (ISD::MUL, VT))
5457
5457
return SDValue ();
5458
5458
5459
5459
bool ComparingWithAllZeros = true ;
@@ -5583,7 +5583,7 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5583
5583
}
5584
5584
5585
5585
if (!ComparingWithAllZeros && !AllComparisonsWithNonZerosAreTautological) {
5586
- if (!isOperationLegalOrCustom (ISD::SUB, VT))
5586
+ if (!DCI. isBeforeLegalizeOps () && ! isOperationLegalOrCustom (ISD::SUB, VT))
5587
5587
return SDValue (); // FIXME: Could/should use `ISD::ADD`?
5588
5588
assert (CompTargetNode.getValueType () == N.getValueType () &&
5589
5589
" Expecting that the types on LHS and RHS of comparisons match." );
@@ -5598,7 +5598,7 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5598
5598
// divisors as a performance improvement, since rotating by 0 is a no-op.
5599
5599
if (HadEvenDivisor) {
5600
5600
// We need ROTR to do this.
5601
- if (!isOperationLegalOrCustom (ISD::ROTR, VT))
5601
+ if (!DCI. isBeforeLegalizeOps () && ! isOperationLegalOrCustom (ISD::ROTR, VT))
5602
5602
return SDValue ();
5603
5603
SDNodeFlags Flags;
5604
5604
Flags.setExact (true );
@@ -5628,6 +5628,8 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5628
5628
DAG.getSetCC (DL, SETCCVT, D, CompTargetNode, ISD::SETULE);
5629
5629
Created.push_back (TautologicalInvertedChannels.getNode ());
5630
5630
5631
+ // NOTE: we avoid letting illegal types through even if we're before legalize
5632
+ // ops – legalization has a hard time producing good code for this.
5631
5633
if (isOperationLegalOrCustom (ISD::VSELECT, SETCCVT)) {
5632
5634
// If we have a vector select, let's replace the comparison results in the
5633
5635
// affected lanes with the correct tautological result.
@@ -5638,6 +5640,8 @@ TargetLowering::prepareUREMEqFold(EVT SETCCVT, SDValue REMNode,
5638
5640
}
5639
5641
5640
5642
// Else, we can just invert the comparison result in the appropriate lanes.
5643
+ //
5644
+ // NOTE: see the note above VSELECT above.
5641
5645
if (isOperationLegalOrCustom (ISD::XOR, SETCCVT))
5642
5646
return DAG.getNode (ISD::XOR, DL, SETCCVT, NewCC,
5643
5647
TautologicalInvertedChannels);
@@ -5692,8 +5696,9 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
5692
5696
EVT ShVT = getShiftAmountTy (VT, DAG.getDataLayout ());
5693
5697
EVT ShSVT = ShVT.getScalarType ();
5694
5698
5695
- // If MUL is unavailable, we cannot proceed in any case.
5696
- if (!isOperationLegalOrCustom (ISD::MUL, VT))
5699
+ // If we are after ops legalization, and MUL is unavailable, we can not
5700
+ // proceed.
5701
+ if (!DCI.isBeforeLegalizeOps () && !isOperationLegalOrCustom (ISD::MUL, VT))
5697
5702
return SDValue ();
5698
5703
5699
5704
// TODO: Could support comparing with non-zero too.
@@ -5848,7 +5853,7 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
5848
5853
5849
5854
if (NeedToApplyOffset) {
5850
5855
// We need ADD to do this.
5851
- if (!isOperationLegalOrCustom (ISD::ADD, VT))
5856
+ if (!DCI. isBeforeLegalizeOps () && ! isOperationLegalOrCustom (ISD::ADD, VT))
5852
5857
return SDValue ();
5853
5858
5854
5859
// (add (mul N, P), A)
@@ -5860,7 +5865,7 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
5860
5865
// divisors as a performance improvement, since rotating by 0 is a no-op.
5861
5866
if (HadEvenDivisor) {
5862
5867
// We need ROTR to do this.
5863
- if (!isOperationLegalOrCustom (ISD::ROTR, VT))
5868
+ if (!DCI. isBeforeLegalizeOps () && ! isOperationLegalOrCustom (ISD::ROTR, VT))
5864
5869
return SDValue ();
5865
5870
SDNodeFlags Flags;
5866
5871
Flags.setExact (true );
@@ -5883,6 +5888,9 @@ TargetLowering::prepareSREMEqFold(EVT SETCCVT, SDValue REMNode,
5883
5888
// we must fix-up results for said lanes.
5884
5889
assert (VT.isVector () && " Can/should only get here for vectors." );
5885
5890
5891
+ // NOTE: we avoid letting illegal types through even if we're before legalize
5892
+ // ops – legalization has a hard time producing good code for the code that
5893
+ // follows.
5886
5894
if (!isOperationLegalOrCustom (ISD::SETEQ, VT) ||
5887
5895
!isOperationLegalOrCustom (ISD::AND, VT) ||
5888
5896
!isOperationLegalOrCustom (Cond, VT) ||
0 commit comments