Skip to content

Commit 00218c1

Browse files
committed
[Analysis] propagate poison through integer min/max intrinsics
A more general enhancement needs to add tests and make sure that intrinsics that return structs are correct. There are also target-specific intrinsics, and I'm not sure what behavior is expected for those.
1 parent 765b5b8 commit 00218c1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,11 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
25062506
case Intrinsic::smin:
25072507
case Intrinsic::umax:
25082508
case Intrinsic::umin:
2509+
// This is the same as for binary ops - poison propagates.
2510+
// TODO: Poison handling should be consolidated.
2511+
if (isa<PoisonValue>(Operands[0]) || isa<PoisonValue>(Operands[1]))
2512+
return PoisonValue::get(Ty);
2513+
25092514
if (!C0 && !C1)
25102515
return UndefValue::get(Ty);
25112516
if (!C0 || !C1)

llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ define i8 @smax() {
291291

292292
define <5 x i8> @smax_vec() {
293293
; CHECK-LABEL: @smax_vec(
294-
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 127, i8 127, i8 42, i8 127>
294+
; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 127, i8 poison, i8 42, i8 127>
295295
;
296296
%r = call <5 x i8> @llvm.smax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 127>)
297297
ret <5 x i8> %r
@@ -307,7 +307,7 @@ define i8 @smin() {
307307

308308
define <5 x i8> @smin_vec() {
309309
; CHECK-LABEL: @smin_vec(
310-
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 -128, i8 -128, i8 42, i8 -127>
310+
; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -128, i8 poison, i8 42, i8 -127>
311311
;
312312
%r = call <5 x i8> @llvm.smin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 129>)
313313
ret <5 x i8> %r
@@ -323,7 +323,7 @@ define i8 @umax() {
323323

324324
define <5 x i8> @umax_vec() {
325325
; CHECK-LABEL: @umax_vec(
326-
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 -1, i8 -1, i8 42, i8 -128>
326+
; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 -1, i8 poison, i8 42, i8 -128>
327327
;
328328
%r = call <5 x i8> @llvm.umax.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)
329329
ret <5 x i8> %r
@@ -339,7 +339,7 @@ define i8 @umin() {
339339

340340
define <5 x i8> @umin_vec() {
341341
; CHECK-LABEL: @umin_vec(
342-
; CHECK-NEXT: ret <5 x i8> <i8 undef, i8 0, i8 0, i8 42, i8 42>
342+
; CHECK-NEXT: ret <5 x i8> <i8 poison, i8 0, i8 poison, i8 42, i8 42>
343343
;
344344
%r = call <5 x i8> @llvm.umin.v5i8(<5 x i8> <i8 poison, i8 undef, i8 1, i8 42, i8 42>, <5 x i8> <i8 undef, i8 1, i8 poison, i8 42, i8 128>)
345345
ret <5 x i8> %r

0 commit comments

Comments
 (0)