[llvm] [InstCombine] Fold trunc(umin/umax(zext(x), y & mask)) to narrower umin/umax (PR #173221)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 27 02:24:44 PST 2025


================
@@ -0,0 +1,76 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i16 @umin(i32 %arg1, i32 %arg2, ptr %arg0) {
+; CHECK-LABEL: define i16 @umin(
+; CHECK-SAME: i32 [[ARG1:%.*]], i32 [[ARG2:%.*]], ptr [[ARG0:%.*]]) {
+; CHECK-NEXT:    [[V0:%.*]] = udiv i32 [[ARG2]], [[ARG1]]
+; CHECK-NEXT:    [[V1:%.*]] = load i16, ptr [[ARG0]], align 2
+; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 [[V0]] to i16
+; CHECK-NEXT:    [[V4:%.*]] = call i16 @llvm.umin.i16(i16 [[TMP1]], i16 [[V1]])
+; CHECK-NEXT:    ret i16 [[V4]]
+;
+  %v0 = udiv i32 %arg2, %arg1
+  %v1 = load i16, ptr %arg0, align 2
----------------
nikic wrote:

Can you please replace these udiv + load with arguments? They don't seem relevant to the transform.

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


More information about the llvm-commits mailing list