[llvm] [DAGCombiner] Fold subtraction if above threshold to `umin` (PR #134235)
Piotr Fusik via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 8 04:34:09 PDT 2025
================
@@ -14895,6 +14895,19 @@ static SDValue performSUBCombine(SDNode *N, SelectionDAG &DAG,
if (SDValue V = combineSubShiftToOrcB(N, DAG, Subtarget))
return V;
+ if (Subtarget.hasStdExtZbb()) {
+ // fold (sub x, (select (ult x, y), 0, y)) -> (umin x, (sub x, y))
----------------
pfusik wrote:
InstCombine replaces your pattern with mine:
```
define dso_local signext i32 @mod(i32 noundef signext %x, i32 noundef signext %y) local_unnamed_addr #0 {
entry:
%cmp = icmp uge i32 %x, %y
%cond = select i1 %cmp, i32 %y, i32 0
%sub = sub i32 %x, %cond
ret i32 %sub
}
; *** IR Dump After InstCombinePass on mod ***
; Function Attrs: nounwind uwtable vscale_range(2,1024)
define dso_local signext i32 @mod(i32 noundef signext %x, i32 noundef signext %y) local_unnamed_addr #0 {
entry:
%cmp.not = icmp ult i32 %x, %y
%cond = select i1 %cmp.not, i32 0, i32 %y
%sub = sub i32 %x, %cond
ret i32 %sub
}
```
https://github.com/llvm/llvm-project/pull/134235
More information about the llvm-commits
mailing list