[llvm] a0e71f1 - [ConstProp] propagate poison from vector reduction element(s) to result

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 07:34:49 PDT 2021


Author: Sanjay Patel
Date: 2021-05-24T10:34:40-04:00
New Revision: a0e71f1832d194baffb25a4e7394b623d2bf97cb

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

LOG: [ConstProp] propagate poison from vector reduction element(s) to result

This follows from the underlying logic for binops and min/max.
Although it does not appear that we handle this for min/max
intrinsics currently.
https://alive2.llvm.org/ce/z/Kq9Xnh

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 948c884b44dfe..7d4fcdc456fec 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1715,7 +1715,7 @@ Constant *constantFoldVectorReduce(Intrinsic::ID IID, Constant *Op) {
     return ConstantInt::get(VT->getElementType(), 0);
 
   // This is the same as the underlying binops - poison propagates.
-  if (isa<PoisonValue>(Op))
+  if (isa<PoisonValue>(Op) || Op->containsPoisonElement())
     return PoisonValue::get(VT->getElementType());
 
   // TODO: Handle undef.

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll b/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll
index 2f0289a9dd2a7..e27180b1a8909 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/vecreduce.ll
@@ -81,8 +81,7 @@ define i32 @add_poison() {
 
 define i32 @add_poison1() {
 ; CHECK-LABEL: @add_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> <i32 1, i32 1, i32 poison, i32 1, i32 1, i32 42, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> <i32 1, i32 1, i32 poison, i32 1, i32 1, i32 42, i32 1, i32 1>)
   ret i32 %x
@@ -148,8 +147,7 @@ define i32 @mul_poison() {
 
 define i32 @mul_poison1() {
 ; CHECK-LABEL: @mul_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.mul.v8i32(<8 x i32> <i32 0, i32 1, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.mul.v8i32(<8 x i32> <i32 0, i32 1, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -215,8 +213,7 @@ define i32 @and_poison() {
 
 define i32 @and_poison1() {
 ; CHECK-LABEL: @and_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.and.v8i32(<8 x i32> <i32 -1, i32 1, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.and.v8i32(<8 x i32> <i32 -1, i32 1, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -282,8 +279,7 @@ define i32 @or_poison() {
 
 define i32 @or_poison1() {
 ; CHECK-LABEL: @or_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> <i32 1, i32 0, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> <i32 1, i32 0, i32 poison, i32 1, i32 1, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -349,8 +345,7 @@ define i32 @xor_poison() {
 
 define i32 @xor_poison1() {
 ; CHECK-LABEL: @xor_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.xor.v8i32(<8 x i32> <i32 poison, i32 1, i32 undef, i32 1, i32 1, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.xor.v8i32(<8 x i32> <i32 poison, i32 1, i32 undef, i32 1, i32 1, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -416,8 +411,7 @@ define i32 @smin_poison() {
 
 define i32 @smin_poison1() {
 ; CHECK-LABEL: @smin_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.smin.v8i32(<8 x i32> <i32 1, i32 1, i32 undef, i32 1, i32 poison, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.smin.v8i32(<8 x i32> <i32 1, i32 1, i32 undef, i32 1, i32 poison, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -483,8 +477,7 @@ define i32 @smax_poison() {
 
 define i32 @smax_poison1() {
 ; CHECK-LABEL: @smax_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.smax.v8i32(<8 x i32> <i32 1, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1, i32 poison>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.smax.v8i32(<8 x i32> <i32 1, i32 1, i32 0, i32 1, i32 1, i32 1, i32 1, i32 poison>)
   ret i32 %x
@@ -550,8 +543,7 @@ define i32 @umin_poison() {
 
 define i32 @umin_poison1() {
 ; CHECK-LABEL: @umin_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.umin.v8i32(<8 x i32> <i32 1, i32 1, i32 -1, i32 poison, i32 1, i32 1, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.umin.v8i32(<8 x i32> <i32 1, i32 1, i32 -1, i32 poison, i32 1, i32 1, i32 1, i32 1>)
   ret i32 %x
@@ -617,8 +609,7 @@ define i32 @umax_poison() {
 
 define i32 @umax_poison1() {
 ; CHECK-LABEL: @umax_poison1(
-; CHECK-NEXT:    [[X:%.*]] = call i32 @llvm.vector.reduce.umax.v8i32(<8 x i32> <i32 1, i32 1, i32 poison, i32 1, i32 1, i32 poison, i32 1, i32 1>)
-; CHECK-NEXT:    ret i32 [[X]]
+; CHECK-NEXT:    ret i32 poison
 ;
   %x = call i32 @llvm.vector.reduce.umax.v8i32(<8 x i32> <i32 1, i32 1, i32 poison, i32 1, i32 1, i32 poison, i32 1, i32 1>)
   ret i32 %x


        


More information about the llvm-commits mailing list