[llvm] [InstCombine] Fold max(max(x, c1) << c2, c3) —> max(x << c2, c3) when c3 >= c1 * 2 ^ c2 (PR #140526)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 01:33:48 PDT 2025


================
@@ -0,0 +1,42 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+;define i32 @src(i32 %x, i32 %shamt, i32 %c) {
+;  %shl = shl nuw i32 %x, %shamt
+;  %c2 = shl nuw i32 %c, %shamt
+;  %max = call i32 @llvm.umin(i32 %shl, i32 %c2)
+;  ret i32 %max
+;}
+
+;define i32 @tgt(i32 %x, i32 %shamt, i32 %c) {
+;  %max = call i32 @llvm.umin(i32 %x, i32 %c)
+;  %shl = shl i32 %max, %shamt
+;  ret i32 %shl
+;}
----------------
dtcxzyw wrote:

```suggestion
```


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


More information about the llvm-commits mailing list