================
@@ -8826,15 +9104,49 @@ SDValue SystemZTargetLowering::combineSELECT_CCMASK(
int CCMaskVal = CCMask->getZExtValue();
SDValue CCReg = N->getOperand(4);
- if (combineCCMask(CCReg, CCValidVal, CCMaskVal))
- return DAG.getNode(SystemZISD::SELECT_CCMASK, SDLoc(N), N->getValueType(0),
- N->getOperand(0), N->getOperand(1),
- DAG.getTargetConstant(CCValidVal, SDLoc(N), MVT::i32),
- DAG.getTargetConstant(CCMaskVal, SDLoc(N), MVT::i32),
- CCReg);
- return SDValue();
-}
+ if (!combineCCMask(CCReg, CCValidVal, CCMaskVal, DCI))
+ return SDValue();
+
+ // Handle TrueVal and FalseVal in outermost select_ccmask.
+ SDValue TrueVal = N->getOperand(0);
+ SDValue FalseVal = N->getOperand(1);
+ const auto &&TrueSDVals = simplifyAssumingCCVal(TrueVal, CCReg, DCI);
+ const auto &&FalseSDVals = simplifyAssumingCCVal(FalseVal, CCReg, DCI);
+ // There might be cases where TrueSDVals and FalseSDVals are empty as
+ // TrueVal and FalseVal both are non-constant, and they have already been
+ // optimized by combineCCMask, we can not take early exit here, just bypass
it
+ // and directly create a new SELECT_CCMASK.
+ if (!TrueSDVals.empty() && !FalseSDVals.empty()) {
+ SmallVector<SDValue, 4> MergedSDVals;
+ for (auto CC : {0, 1, 2, 3}) {
+ MergedSDVals.emplace_back(((CCMaskVal & (1 << (3 - CC))) != 0) &&
+ ((CCValidVal & (1 << (3 - CC))) != 0)
+ ? TrueSDVals[CC]
+ : FalseSDVals[CC]);
+ }
+ SmallSet<SDValue, 4> MergedSDValsSet(MergedSDVals.begin(),
+ MergedSDVals.end());
+ if (MergedSDValsSet.size() != 2)
+ return SDValue();
+ auto BeginIt = MergedSDValsSet.begin();
+ SDValue NewTrueVal = *BeginIt, NewFalseVal = *next(BeginIt);
+ if (NewTrueVal == FalseVal || NewFalseVal == TrueVal)
+ std::swap(NewTrueVal, NewFalseVal);
+ int NewCCMask = 0;
+ for (auto CC : {0, 1, 2, 3}) {
+ NewCCMask <<= 1;
+ NewCCMask |= MergedSDVals[CC] == NewTrueVal;
+ }
+ CCMaskVal = NewCCMask;
----------------
uweigand wrote:
Should restrict the new CCMask to CCValid here.
https://github.com/llvm/llvm-project/pull/125970
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits