Skip to content

Commit c401feb

Browse files
lukel97IanWood1
authored andcommitted
[InstSimplify] Fold {u,s}{min,max} x, poison -> poison (llvm#138166)
Following from the discussion in llvm#138095 (comment), these intrinsics are poison if any of their operands are poison, and are marked as such in propagatesPoison in ValueTracking.cpp. This will help fold away leftover vectors produced by VectorCombine when scalarizing intrinsics.
1 parent c78d061 commit c401feb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6541,6 +6541,10 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
65416541
if (match(Op0, m_ImmConstant()))
65426542
std::swap(Op0, Op1);
65436543

6544+
// Propagate poison.
6545+
if (isa<PoisonValue>(Op1))
6546+
return Op1;
6547+
65446548
// Assume undef is the limit value.
65456549
if (Q.isUndefValue(Op1))
65466550
return ConstantInt::get(

llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ define i81 @smax_undef(i81 %x) {
7575

7676
define i81 @smax_poison(i81 %x) {
7777
; CHECK-LABEL: @smax_poison(
78-
; CHECK-NEXT: ret i81 1208925819614629174706175
78+
; CHECK-NEXT: ret i81 poison
7979
;
8080
%r = call i81 @llvm.smax.i81(i81 poison, i81 %x)
8181
ret i81 %r
@@ -91,7 +91,7 @@ define i3 @smin_undef(i3 %x) {
9191

9292
define i3 @smin_poison(i3 %x) {
9393
; CHECK-LABEL: @smin_poison(
94-
; CHECK-NEXT: ret i3 -4
94+
; CHECK-NEXT: ret i3 poison
9595
;
9696
%r = call i3 @llvm.smin.i3(i3 %x, i3 poison)
9797
ret i3 %r
@@ -107,7 +107,7 @@ define <2 x i8> @umax_undef(<2 x i8> %x) {
107107

108108
define <2 x i8> @umax_poison(<2 x i8> %x) {
109109
; CHECK-LABEL: @umax_poison(
110-
; CHECK-NEXT: ret <2 x i8> splat (i8 -1)
110+
; CHECK-NEXT: ret <2 x i8> poison
111111
;
112112
%r = call <2 x i8> @llvm.umax.v2i8(<2 x i8> poison, <2 x i8> %x)
113113
ret <2 x i8> %r
@@ -123,7 +123,7 @@ define <2 x i8> @umin_undef(<2 x i8> %x) {
123123

124124
define <2 x i8> @umin_poison(<2 x i8> %x) {
125125
; CHECK-LABEL: @umin_poison(
126-
; CHECK-NEXT: ret <2 x i8> zeroinitializer
126+
; CHECK-NEXT: ret <2 x i8> poison
127127
;
128128
%r = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> poison)
129129
ret <2 x i8> %r

0 commit comments

Comments
 (0)