[llvm] 00218c1 - [Analysis] propagate poison through integer min/max intrinsics

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 07:47:07 PST 2022


Author: Sanjay Patel
Date: 2022-02-15T10:45:32-05:00
New Revision: 00218c188b75485ff1c9607c862e9f91663267a5

URL: https://github.com/llvm/llvm-project/commit/00218c188b75485ff1c9607c862e9f91663267a5
DIFF: https://github.com/llvm/llvm-project/commit/00218c188b75485ff1c9607c862e9f91663267a5.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a21d3cec37e48..b5169e540df73 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2506,6 +2506,11 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
     case Intrinsic::smin:
     case Intrinsic::umax:
     case Intrinsic::umin:
+      // This is the same as for binary ops - poison propagates.
+      // TODO: Poison handling should be consolidated.
+      if (isa<PoisonValue>(Operands[0]) || isa<PoisonValue>(Operands[1]))
+        return PoisonValue::get(Ty);
+
       if (!C0 && !C1)
         return UndefValue::get(Ty);
       if (!C0 || !C1)

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll b/llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll
index 6196333844758..a5f5d4e12ed84 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/min-max.ll
@@ -291,7 +291,7 @@ define i8 @smax() {
 
 define <5 x i8> @smax_vec() {
 ; CHECK-LABEL: @smax_vec(
-; CHECK-NEXT:    ret <5 x i8> <i8 undef, i8 127, i8 127, i8 42, i8 127>
+; CHECK-NEXT:    ret <5 x i8> <i8 poison, i8 127, i8 poison, i8 42, i8 127>
 ;
   %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>)
   ret <5 x i8> %r
@@ -307,7 +307,7 @@ define i8 @smin() {
 
 define <5 x i8> @smin_vec() {
 ; CHECK-LABEL: @smin_vec(
-; CHECK-NEXT:    ret <5 x i8> <i8 undef, i8 -128, i8 -128, i8 42, i8 -127>
+; CHECK-NEXT:    ret <5 x i8> <i8 poison, i8 -128, i8 poison, i8 42, i8 -127>
 ;
   %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>)
   ret <5 x i8> %r
@@ -323,7 +323,7 @@ define i8 @umax() {
 
 define <5 x i8> @umax_vec() {
 ; CHECK-LABEL: @umax_vec(
-; CHECK-NEXT:    ret <5 x i8> <i8 undef, i8 -1, i8 -1, i8 42, i8 -128>
+; CHECK-NEXT:    ret <5 x i8> <i8 poison, i8 -1, i8 poison, i8 42, i8 -128>
 ;
   %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>)
   ret <5 x i8> %r
@@ -339,7 +339,7 @@ define i8 @umin() {
 
 define <5 x i8> @umin_vec() {
 ; CHECK-LABEL: @umin_vec(
-; CHECK-NEXT:    ret <5 x i8> <i8 undef, i8 0, i8 0, i8 42, i8 42>
+; CHECK-NEXT:    ret <5 x i8> <i8 poison, i8 0, i8 poison, i8 42, i8 42>
 ;
   %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>)
   ret <5 x i8> %r


        


More information about the llvm-commits mailing list