[llvm] [DAGCombiner] Fold subtraction if above a constant threshold to `umin` (PR #135194)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Thu May 15 03:01:33 PDT 2025


================
@@ -12074,6 +12078,17 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
 
     if (SDValue NewSel = SimplifySelect(DL, N0, N1, N2))
       return NewSel;
+
+    // (select (ugt x, C), (add x, ~C), x) -> (umin (add x, ~C), x)
----------------
pfusik wrote:

Thanks!

> Maybe it is enough to freeze the ADD operand (as the comparison would be poison if x is poison)?

I'm new to alive2, but I think it shows it won't work. The transform relies on an unsigned overflow.

I'll prepare a patch recreating the `add` with no `nuw/nsw`.

https://github.com/llvm/llvm-project/pull/135194


More information about the llvm-commits mailing list