[llvm] [Gisel] smin/umin optimization rewrites (PR #203939)
Luisa Cicolini via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 04:26:58 PDT 2026
================
@@ -156,3 +156,158 @@ body: |
%mul:_(s64) = G_MUL %max, %sub2
$x0 = COPY %mul
RET_ReallyLR implicit $x0
+
+...
+---
+name: ASubSMin
+body: |
+ bb.0:
+ liveins: $x0
+
+
+ ; CHECK-LABEL: name: ASubSMin
+ ; CHECK: liveins: $x0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(s64) = COPY $x0
+ ; CHECK-NEXT: %zero:_(s64) = G_CONSTANT i64 0
+ ; CHECK-NEXT: [[SUB:%[0-9]+]]:_(s64) = G_SUB %zero, %a
+ ; CHECK-NEXT: %sub2:_(s64) = G_SMAX %a, [[SUB]]
+ ; CHECK-NEXT: $x0 = COPY %sub2(s64)
+ ; CHECK-NEXT: RET_ReallyLR implicit $x0
+ %a:_(s64) = COPY $x0
+ %zero:_(s64) = G_CONSTANT i64 0
+ %sub1:_(s64) = G_SUB %zero, %a
+ %max:_(s64) = G_SMIN %a, %sub1
+ %sub2:_(s64) = G_SUB %zero, %max
+ $x0 = COPY %sub2
+ RET_ReallyLR implicit $x0
+
+...
+---
+name: ASubSMinVec
+body: |
+ bb.0:
+ liveins: $q0
+
+ ; CHECK-LABEL: name: ASubSMinVec
+ ; CHECK: liveins: $q0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(<4 x s32>) = COPY $q0
+ ; CHECK-NEXT: %c:_(s32) = G_CONSTANT i32 0
+ ; CHECK-NEXT: %c1:_(<4 x s32>) = G_BUILD_VECTOR %c(s32), %c(s32), %c(s32), %c(s32)
+ ; CHECK-NEXT: [[SUB:%[0-9]+]]:_(<4 x s32>) = G_SUB %c1, %a
+ ; CHECK-NEXT: %sub2:_(<4 x s32>) = G_SMAX %a, [[SUB]]
+ ; CHECK-NEXT: $q0 = COPY %sub2(<4 x s32>)
+ ; CHECK-NEXT: RET_ReallyLR implicit $q0
+ %a:_(<4 x s32>) = COPY $q0
+ %c:_(s32) = G_CONSTANT i32 0
+ %c1:_(<4 x s32>) = G_BUILD_VECTOR %c(s32), %c(s32), %c(s32), %c(s32)
+ %sub1:_(<4 x s32>) = G_SUB %c1, %a
+ %max:_(<4 x s32>) = G_SMIN %a, %sub1
+ %sub2:_(<4 x s32>) = G_SUB %c1, %max
+ $q0 = COPY %sub2
+ RET_ReallyLR implicit $q0
+
+...
+---
+name: ASubSMinOneUse
+body: |
+ bb.0:
+ liveins: $x0
+
+ ; CHECK-LABEL: name: ASubSMinOneUse
+ ; CHECK: liveins: $x0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(s64) = COPY $x0
+ ; CHECK-NEXT: %zero:_(s64) = G_CONSTANT i64 0
+ ; CHECK-NEXT: %sub1:_(s64) = G_SUB %zero, %a
+ ; CHECK-NEXT: %max:_(s64) = G_SMIN %a, %sub1
+ ; CHECK-NEXT: %sub2:_(s64) = G_SUB %zero, %max
+ ; CHECK-NEXT: %mul:_(s64) = G_MUL %max, %sub2
+ ; CHECK-NEXT: $x0 = COPY %mul(s64)
+ ; CHECK-NEXT: RET_ReallyLR implicit $x0
+ %a:_(s64) = COPY $x0
+ %zero:_(s64) = G_CONSTANT i64 0
+ %sub1:_(s64) = G_SUB %zero, %a
+ %max:_(s64) = G_SMIN %a, %sub1
+ %sub2:_(s64) = G_SUB %zero, %max
+ %mul:_(s64) = G_MUL %max, %sub2
+ $x0 = COPY %mul
+ RET_ReallyLR implicit $x0
+
+...
+---
+name: ASubUMin
+body: |
+ bb.0:
+ liveins: $x0
+
+ ; CHECK-LABEL: name: ASubUMin
+ ; CHECK: liveins: $x0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(s64) = COPY $x0
+ ; CHECK-NEXT: %zero:_(s64) = G_CONSTANT i64 0
+ ; CHECK-NEXT: [[SUB:%[0-9]+]]:_(s64) = G_SUB %zero, %a
+ ; CHECK-NEXT: %sub2:_(s64) = G_UMAX %a, [[SUB]]
+ ; CHECK-NEXT: $x0 = COPY %sub2(s64)
+ ; CHECK-NEXT: RET_ReallyLR implicit $x0
+ %a:_(s64) = COPY $x0
+ %zero:_(s64) = G_CONSTANT i64 0
+ %sub1:_(s64) = G_SUB %zero, %a
+ %max:_(s64) = G_UMIN %a, %sub1
+ %sub2:_(s64) = G_SUB %zero, %max
+ $x0 = COPY %sub2
+ RET_ReallyLR implicit $x0
+
+...
+---
+name: ASubUMinVec
+body: |
+ bb.0:
+ liveins: $q0
+
+ ; CHECK-LABEL: name: ASubUMinVec
+ ; CHECK: liveins: $q0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(<4 x s32>) = COPY $q0
+ ; CHECK-NEXT: %c:_(s32) = G_CONSTANT i32 0
+ ; CHECK-NEXT: %c1:_(<4 x s32>) = G_BUILD_VECTOR %c(s32), %c(s32), %c(s32), %c(s32)
+ ; CHECK-NEXT: [[SUB:%[0-9]+]]:_(<4 x s32>) = G_SUB %c1, %a
+ ; CHECK-NEXT: %sub2:_(<4 x s32>) = G_UMAX %a, [[SUB]]
+ ; CHECK-NEXT: $q0 = COPY %sub2(<4 x s32>)
+ ; CHECK-NEXT: RET_ReallyLR implicit $q0
+ %a:_(<4 x s32>) = COPY $q0
+ %c:_(s32) = G_CONSTANT i32 0
+ %c1:_(<4 x s32>) = G_BUILD_VECTOR %c(s32), %c(s32), %c(s32), %c(s32)
+ %sub1:_(<4 x s32>) = G_SUB %c1, %a
+ %max:_(<4 x s32>) = G_UMIN %a, %sub1
+ %sub2:_(<4 x s32>) = G_SUB %c1, %max
+ $q0 = COPY %sub2
+ RET_ReallyLR implicit $q0
+
+...
+---
+name: ASubUMinOneUse
+body: |
+ bb.0:
+ liveins: $x0
+
+ ; CHECK-LABEL: name: ASubUMinOneUse
+ ; CHECK: liveins: $x0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %a:_(s64) = COPY $x0
+ ; CHECK-NEXT: %zero:_(s64) = G_CONSTANT i64 0
+ ; CHECK-NEXT: %sub1:_(s64) = G_SUB %zero, %a
+ ; CHECK-NEXT: %max:_(s64) = G_UMIN %a, %sub1
+ ; CHECK-NEXT: %sub2:_(s64) = G_SUB %zero, %max
+ ; CHECK-NEXT: %mul:_(s64) = G_MUL %max, %sub2
+ ; CHECK-NEXT: $x0 = COPY %mul(s64)
+ ; CHECK-NEXT: RET_ReallyLR implicit $x0
+ %a:_(s64) = COPY $x0
+ %zero:_(s64) = G_CONSTANT i64 0
+ %sub1:_(s64) = G_SUB %zero, %a
+ %max:_(s64) = G_UMIN %a, %sub1
+ %sub2:_(s64) = G_SUB %zero, %max
+ %mul:_(s64) = G_MUL %max, %sub2
+ $x0 = COPY %mul
+ RET_ReallyLR implicit $x0
----------------
luisacicolini wrote:
added
https://github.com/llvm/llvm-project/pull/203939
More information about the llvm-commits
mailing list