[llvm] [SDAG] SetCC: remove spurious extensions (PR #173110)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 11 06:55:11 PST 2026
================
@@ -14148,6 +14148,34 @@ SDValue DAGCombiner::visitSETCC(SDNode *N) {
}
}
}
+
+ // (setcc (zext a), (zext b), setu??) -> (setcc a, b, setu??)
+ // (setcc (sext a), (sext b), sets??) -> (setcc a, b, sets??)
+ if ((ISD::isUnsignedIntSetCC(Cond) && N0.getOpcode() == ISD::ZERO_EXTEND &&
+ N1.getOpcode() == ISD::ZERO_EXTEND) ||
+ (ISD::isSignedIntSetCC(Cond) && N0.getOpcode() == ISD::SIGN_EXTEND &&
+ N1.getOpcode() == ISD::SIGN_EXTEND)) {
+ SDValue LHS = N0.getOperand(0), RHS = N1.getOperand(0);
+ EVT SmallVT =
+ LHS.getScalarValueSizeInBits() > RHS.getScalarValueSizeInBits()
+ ? LHS.getValueType()
+ : RHS.getValueType();
+ if (!LegalOperations ||
+ (SmallVT.isSimple() &&
+ TLI.isCondCodeLegal(Cond, SmallVT.getSimpleVT()))) {
+ LHS = DAG.getExtOrTrunc(ISD::isSignedIntSetCC(Cond), LHS, SDLoc(LHS),
+ SmallVT);
+ RHS = DAG.getExtOrTrunc(ISD::isSignedIntSetCC(Cond), RHS, SDLoc(RHS),
+ SmallVT);
+ SDValue NewSetCC =
+ DAG.getSetCC(DL, getSetCCResultType(SmallVT), LHS, RHS, Cond);
----------------
DaKnig wrote:
can you elaborate on what you mean by "source types are not the same"? in what case does that happen?
https://github.com/llvm/llvm-project/pull/173110
More information about the llvm-commits
mailing list