[llvm] [AArch64][SelectionDAG][SVE] Fold following extend(icmp) patterns (PR #192052)
Sushant Gokhale via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 22:04:50 PDT 2026
================
@@ -24422,6 +24437,105 @@ static SDValue performExtendCombine(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI,
SelectionDAG &DAG,
const AArch64Subtarget *Subtarget) {
+ // sext(icmp slt a, b) --> asr (shsub a, b), bitwidth-1
+ // sext(icmp ult a, b) --> asr (uhsub a, b), bitwidth-1
+ // zext(icmp slt a, b) --> lsr (shsub a, b), bitwidth-1
+ // zext(icmp ult a, b) --> lsr (uhsub a, b), bitwidth-1
+ // sext(icmp sgt a, b) --> asr (shsub b, a), bitwidth-1
+ // sext(icmp ugt a, b) --> asr (uhsub b, a), bitwidth-1
+ // zext(icmp sgt a, b) --> lsr (shsub b, a), bitwidth-1
+ // zext(icmp ugt a, b) --> lsr (uhsub b, a), bitwidth-1
+ SDValue Compare = N->getOperand(0);
+ SDLoc DL(N);
+ if (Compare.getOpcode() == AArch64ISD::SETCC_MERGE_ZERO &&
----------------
sushgokh wrote:
Having all true pred creates one more `ptrue` instruction in addition to what is already present for `cmphi` instruction and ptrue is not very cheap(lat=2). Rather, I am using the same pred as the `cmp` instruction.
Regarding one use, the compare instruction isnt eliminated here. It remains if there are other uses of it. I am just intercepting the extend instruction.
https://github.com/llvm/llvm-project/pull/192052
More information about the llvm-commits
mailing list