[llvm] [PowerPC] Lower ucmp using subtractions (PR #146446)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 25 05:08:30 PDT 2025
================
@@ -12521,6 +12525,33 @@ SDValue PPCTargetLowering::LowerSSUBO(SDValue Op, SelectionDAG &DAG) const {
return DAG.getMergeValues({Sub, OverflowTrunc}, dl);
}
+// Lower unsigned 3-way compare producing -1/0/1.
+SDValue PPCTargetLowering::LowerUCMP(SDValue Op, SelectionDAG &DAG) const {
+ SDLoc DL(Op);
+ SDValue A = DAG.getFreeze(Op.getOperand(0));
+ SDValue B = DAG.getFreeze(Op.getOperand(1));
+ EVT OpVT = A.getValueType(); // operand type
+ EVT ResVT = Op.getValueType(); // result type
+
+ // First compute diff = A - B (will become subf).
+ SDValue Diff = DAG.getNode(ISD::SUB, DL, OpVT, A, B);
+
+ // Generate B - A using SUBC to capture carry.
+ SDVTList VTs = DAG.getVTList(OpVT, MVT::i32);
+ SDValue SubC = DAG.getNode(PPCISD::SUBC, DL, VTs, B, A);
----------------
AZero13 wrote:
> Are PPC SUBC/SUBE just the same as the normal sub-with-overflow, just with glue? Can this be a generic expansion with those instead, and transform those into the target glue nodes?
NO.
Sube on PowerPC has a unique characteristic. It's not a-b-carry, it's a - b + carry.
Because of this, only PowerPC gets to have a lowering like this.
https://github.com/llvm/llvm-project/pull/146446
More information about the llvm-commits
mailing list