forked from OSchip/llvm-project
[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
This commit is contained in:
parent
3dd2063671
commit
a0e71f1832
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue