[llvm] [VectorCombine] Scalarize binop-like intrinsics (PR #138095)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu May 1 09:34:11 PDT 2025
================
@@ -0,0 +1,97 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -S -p vector-combine | FileCheck %s
+
+define <4 x i32> @umax_fixed(i32 %x, i32 %y) {
+; CHECK-LABEL: define <4 x i32> @umax_fixed(
+; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
+; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]])
+; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.umax.v4i32(<4 x i32> poison, <4 x i32> poison)
----------------
lukel97 wrote:
Thanks! And apologies for the noise here, but another thing that I'm also noticing here is that even though instsimplify doesn't currently fold min/max away to poison, it will propagate the poison through insertelement, but only for fixed-length vectors. I think there's a discrepancy here between fixed and scalable:
```llvm
define <4 x i32> @smax_fixed_insert(i32 %x) {
; CHECK-LABEL: define <4 x i32> @smax_fixed_insert(
; CHECK-SAME: i32 [[X:%.*]]) {
; CHECK-NEXT: [[Z:%.*]] = call i32 @llvm.smax.i32(i32 1, i32 [[X]])
; CHECK-NEXT: [[W:%.*]] = insertelement <4 x i32> poison, i32 [[Z]], i64 0
; CHECK-NEXT: ret <4 x i32> [[W]]
;
%z = call i32 @llvm.smax(i32 1, i32 %x)
%v = call <4 x i32> @llvm.smax(<4 x i32> splat (i32 1), <4 x i32> poison)
%w = insertelement <4 x i32> %v, i32 %z, i64 0
ret <4 x i32> %w
}
define <vscale x 4 x i32> @smax_scalable_insert(i32 %x) {
; CHECK-LABEL: define <vscale x 4 x i32> @smax_scalable_insert(
; CHECK-SAME: i32 [[X:%.*]]) {
; CHECK-NEXT: [[Z:%.*]] = call i32 @llvm.smax.i32(i32 1, i32 [[X]])
; CHECK-NEXT: [[V:%.*]] = call <vscale x 4 x i32> @llvm.smax.nxv4i32(<vscale x 4 x i32> splat (i32 1), <vscale x 4 x i32> poison)
; CHECK-NEXT: [[W:%.*]] = insertelement <vscale x 4 x i32> [[V]], i32 [[Z]], i64 0
; CHECK-NEXT: ret <vscale x 4 x i32> [[W]]
;
%z = call i32 @llvm.smax(i32 1, i32 %x)
%v = call <vscale x 4 x i32> @llvm.smax(<vscale x 4 x i32> splat (i32 1), <vscale x 4 x i32> poison)
%w = insertelement <vscale x 4 x i32> %v, i32 %z, i64 0
ret <vscale x 4 x i32> %w
}
```
But I will go ahead and prepare a patch to propagate it through InstructionSimplify.
https://github.com/llvm/llvm-project/pull/138095
More information about the llvm-commits
mailing list