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

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Thu May 15 02:41:23 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)
----------------
bjope wrote:

I think this shows the problem: https://alive2.llvm.org/ce/z/fmKmiZ

One either need to freeze the UMIN operands, or make sure that N1 and N2 is guaranteed not to be poison when doing this transform. Maybe it is enough to freeze the ADD operand (as the comparison would be poison if x is poison)?

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


More information about the llvm-commits mailing list