1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[InstSimplify] Add tests that fold instructions with poison operands (NFC)

This commit is contained in:
Juneyoung Lee 2020-12-02 01:01:42 +09:00
parent c96423a30c
commit 37d6671aa8
23 changed files with 920 additions and 9 deletions

View File

@ -30,7 +30,7 @@ define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
define i8 @knownnegation(i8 %x, i8 %y) {
; CHECK-LABEL: @knownnegation(
; CHECK-NEXT: ret i8 0
; CHECK-NEXT: ret i8 0
;
%xy = sub i8 %x, %y
%yx = sub i8 %y, %x
@ -48,4 +48,10 @@ define <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) {
ret <2 x i8> %r
}
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 poison
;
%y = add i32 %x, poison
ret i32 %y
}

View File

@ -0,0 +1,12 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; TODO: this should be poison
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 0
;
%v = and i32 %x, poison
ret i32 %v
}

View File

@ -35,6 +35,14 @@ define {i8, i1} @test_uadd3(i8 %v) {
ret {i8, i1} %result
}
define {i8, i1} @test_uadd3_poison(i8 %v) {
; CHECK-LABEL: @test_uadd3_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 poison)
ret {i8, i1} %result
}
define {i8, i1} @test_uadd4(i8 %v) {
; CHECK-LABEL: @test_uadd4(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
@ -43,6 +51,14 @@ define {i8, i1} @test_uadd4(i8 %v) {
ret {i8, i1} %result
}
define {i8, i1} @test_uadd4_poison(i8 %v) {
; CHECK-LABEL: @test_uadd4_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 poison, i8 %v)
ret {i8, i1} %result
}
define i1 @test_sadd1() {
; CHECK-LABEL: @test_sadd1(
; CHECK-NEXT: ret i1 true
@ -69,6 +85,14 @@ define {i8, i1} @test_sadd3(i8 %v) {
ret {i8, i1} %result
}
define {i8, i1} @test_sadd3_poison(i8 %v) {
; CHECK-LABEL: @test_sadd3_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 poison)
ret {i8, i1} %result
}
define {i8, i1} @test_sadd4(i8 %v) {
; CHECK-LABEL: @test_sadd4(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
@ -77,6 +101,14 @@ define {i8, i1} @test_sadd4(i8 %v) {
ret {i8, i1} %result
}
define {i8, i1} @test_sadd4_poison(i8 %v) {
; CHECK-LABEL: @test_sadd4_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 poison, i8 %v)
ret {i8, i1} %result
}
define {i8, i1} @test_usub1(i8 %V) {
; CHECK-LABEL: @test_usub1(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -93,6 +125,14 @@ define {i8, i1} @test_usub2(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_usub2_poison(i8 %V) {
; CHECK-LABEL: @test_usub2_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 poison)
ret {i8, i1} %x
}
define {i8, i1} @test_usub3(i8 %V) {
; CHECK-LABEL: @test_usub3(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
@ -101,6 +141,14 @@ define {i8, i1} @test_usub3(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_usub3_poison(i8 %V) {
; CHECK-LABEL: @test_usub3_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 poison, i8 %V)
ret {i8, i1} %x
}
define {i8, i1} @test_ssub1(i8 %V) {
; CHECK-LABEL: @test_ssub1(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -117,6 +165,14 @@ define {i8, i1} @test_ssub2(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_ssub2_poison(i8 %V) {
; CHECK-LABEL: @test_ssub2_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 poison)
ret {i8, i1} %x
}
define {i8, i1} @test_ssub3(i8 %V) {
; CHECK-LABEL: @test_ssub3(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
@ -125,6 +181,14 @@ define {i8, i1} @test_ssub3(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_ssub3_poison(i8 %V) {
; CHECK-LABEL: @test_ssub3_poison(
; CHECK-NEXT: ret { i8, i1 } { i8 undef, i1 false }
;
%x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 poison, i8 %V)
ret {i8, i1} %x
}
define {i8, i1} @test_umul1(i8 %V) {
; CHECK-LABEL: @test_umul1(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -141,6 +205,14 @@ define {i8, i1} @test_umul2(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_umul2_poison(i8 %V) {
; CHECK-LABEL: @test_umul2_poison(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
;
%x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 poison)
ret {i8, i1} %x
}
define {i8, i1} @test_umul3(i8 %V) {
; CHECK-LABEL: @test_umul3(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -157,6 +229,14 @@ define {i8, i1} @test_umul4(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_umul4_poison(i8 %V) {
; CHECK-LABEL: @test_umul4_poison(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
;
%x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 poison, i8 %V)
ret {i8, i1} %x
}
define {i8, i1} @test_smul1(i8 %V) {
; CHECK-LABEL: @test_smul1(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -173,6 +253,14 @@ define {i8, i1} @test_smul2(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_smul2_poison(i8 %V) {
; CHECK-LABEL: @test_smul2_poison(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
;
%x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 poison)
ret {i8, i1} %x
}
define {i8, i1} @test_smul3(i8 %V) {
; CHECK-LABEL: @test_smul3(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
@ -189,6 +277,14 @@ define {i8, i1} @test_smul4(i8 %V) {
ret {i8, i1} %x
}
define {i8, i1} @test_smul4_poison(i8 %V) {
; CHECK-LABEL: @test_smul4_poison(
; CHECK-NEXT: ret { i8, i1 } zeroinitializer
;
%x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 poison, i8 %V)
ret {i8, i1} %x
}
; Test a non-intrinsic that we know about as a library call.
declare float @fabs(float %x)
@ -742,6 +838,108 @@ define i9 @fshr_shift_undef(i9 %x, i9 %y) {
ret i9 %r
}
; If one of operands is poison, the result is poison
; TODO: these should be poison
define i8 @fshl_ops_poison(i8 %b, i8 %shamt) {
; CHECK-LABEL: @fshl_ops_poison(
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 poison, i8 [[B:%.*]], i8 [[SHAMT:%.*]])
; CHECK-NEXT: ret i8 [[R]]
;
%r = call i8 @llvm.fshl.i8(i8 poison, i8 %b, i8 %shamt)
ret i8 %r
}
define i8 @fshl_ops_poison2(i8 %shamt) {
; CHECK-LABEL: @fshl_ops_poison2(
; CHECK-NEXT: ret i8 undef
;
%r = call i8 @llvm.fshl.i8(i8 poison, i8 undef, i8 %shamt)
ret i8 %r
}
define i8 @fshl_ops_poison3(i8 %a, i8 %shamt) {
; CHECK-LABEL: @fshl_ops_poison3(
; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.fshl.i8(i8 [[A:%.*]], i8 poison, i8 [[SHAMT:%.*]])
; CHECK-NEXT: ret i8 [[R]]
;
%r = call i8 @llvm.fshl.i8(i8 %a, i8 poison, i8 %shamt)
ret i8 %r
}
define i8 @fshl_ops_poison4(i8 %shamt) {
; CHECK-LABEL: @fshl_ops_poison4(
; CHECK-NEXT: ret i8 undef
;
%r = call i8 @llvm.fshl.i8(i8 undef, i8 poison, i8 %shamt)
ret i8 %r
}
define i8 @fshl_ops_poison5(i8 %a, i8 %b) {
; CHECK-LABEL: @fshl_ops_poison5(
; CHECK-NEXT: ret i8 [[A:%.*]]
;
%r = call i8 @llvm.fshl.i8(i8 %a, i8 %b, i8 poison)
ret i8 %r
}
define i8 @fshl_ops_poison6() {
; CHECK-LABEL: @fshl_ops_poison6(
; CHECK-NEXT: ret i8 undef
;
%r = call i8 @llvm.fshl.i8(i8 undef, i8 undef, i8 poison)
ret i8 %r
}
define i9 @fshr_ops_poison(i9 %b, i9 %shamt) {
; CHECK-LABEL: @fshr_ops_poison(
; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 poison, i9 [[B:%.*]], i9 [[SHAMT:%.*]])
; CHECK-NEXT: ret i9 [[R]]
;
%r = call i9 @llvm.fshr.i9(i9 poison, i9 %b, i9 %shamt)
ret i9 %r
}
define i9 @fshr_ops_poison2(i9 %shamt) {
; CHECK-LABEL: @fshr_ops_poison2(
; CHECK-NEXT: ret i9 undef
;
%r = call i9 @llvm.fshr.i9(i9 poison, i9 undef, i9 %shamt)
ret i9 %r
}
define i9 @fshr_ops_poison3(i9 %a, i9 %shamt) {
; CHECK-LABEL: @fshr_ops_poison3(
; CHECK-NEXT: [[R:%.*]] = call i9 @llvm.fshr.i9(i9 [[A:%.*]], i9 poison, i9 [[SHAMT:%.*]])
; CHECK-NEXT: ret i9 [[R]]
;
%r = call i9 @llvm.fshr.i9(i9 %a, i9 poison, i9 %shamt)
ret i9 %r
}
define i9 @fshr_ops_poison4(i9 %shamt) {
; CHECK-LABEL: @fshr_ops_poison4(
; CHECK-NEXT: ret i9 undef
;
%r = call i9 @llvm.fshr.i9(i9 undef, i9 poison, i9 %shamt)
ret i9 %r
}
define i9 @fshr_ops_poison5(i9 %a, i9 %b) {
; CHECK-LABEL: @fshr_ops_poison5(
; CHECK-NEXT: ret i9 [[B:%.*]]
;
%r = call i9 @llvm.fshr.i9(i9 %a, i9 %b, i9 poison)
ret i9 %r
}
define i9 @fshr_ops_poison6() {
; CHECK-LABEL: @fshr_ops_poison6(
; CHECK-NEXT: ret i9 undef
;
%r = call i9 @llvm.fshr.i9(i9 undef, i9 undef, i9 poison)
ret i9 %r
}
declare double @llvm.fma.f64(double,double,double)
declare double @llvm.fmuladd.f64(double,double,double)
@ -753,6 +951,14 @@ define double @fma_undef_op0(double %x, double %y) {
ret double %r
}
define double @fma_poison_op0(double %x, double %y) {
; CHECK-LABEL: @fma_poison_op0(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fma.f64(double poison, double %x, double %y)
ret double %r
}
define double @fma_undef_op1(double %x, double %y) {
; CHECK-LABEL: @fma_undef_op1(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -761,6 +967,14 @@ define double @fma_undef_op1(double %x, double %y) {
ret double %r
}
define double @fma_poison_op1(double %x, double %y) {
; CHECK-LABEL: @fma_poison_op1(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fma.f64(double %x, double poison, double %y)
ret double %r
}
define double @fma_undef_op2(double %x, double %y) {
; CHECK-LABEL: @fma_undef_op2(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -769,6 +983,14 @@ define double @fma_undef_op2(double %x, double %y) {
ret double %r
}
define double @fma_poison_op2(double %x, double %y) {
; CHECK-LABEL: @fma_poison_op2(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fma.f64(double %x, double %y, double poison)
ret double %r
}
define double @fmuladd_undef_op0(double %x, double %y) {
; CHECK-LABEL: @fmuladd_undef_op0(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -777,6 +999,14 @@ define double @fmuladd_undef_op0(double %x, double %y) {
ret double %r
}
define double @fmuladd_poison_op0(double %x, double %y) {
; CHECK-LABEL: @fmuladd_poison_op0(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fmuladd.f64(double poison, double %x, double %y)
ret double %r
}
define double @fmuladd_undef_op1(double %x, double %y) {
; CHECK-LABEL: @fmuladd_undef_op1(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -785,6 +1015,14 @@ define double @fmuladd_undef_op1(double %x, double %y) {
ret double %r
}
define double @fmuladd_poison_op1(double %x, double %y) {
; CHECK-LABEL: @fmuladd_poison_op1(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fmuladd.f64(double %x, double poison, double %y)
ret double %r
}
define double @fmuladd_undef_op2(double %x, double %y) {
; CHECK-LABEL: @fmuladd_undef_op2(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -793,6 +1031,14 @@ define double @fmuladd_undef_op2(double %x, double %y) {
ret double %r
}
define double @fmuladd_poison_op2(double %x, double %y) {
; CHECK-LABEL: @fmuladd_poison_op2(
; CHECK-NEXT: ret double 0x7FF8000000000000
;
%r = call double @llvm.fmuladd.f64(double %x, double %y, double poison)
ret double %r
}
define double @fma_nan_op0(double %x, double %y) {
; CHECK-LABEL: @fma_nan_op0(
; CHECK-NEXT: ret double 0x7FF8000000000000
@ -1043,7 +1289,7 @@ define i32 @call_undef_musttail() {
define float @nobuiltin_fmax() {
; CHECK-LABEL: @nobuiltin_fmax(
; CHECK-NEXT: [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) #3
; CHECK-NEXT: [[M:%.*]] = call float @fmaxf(float 0.000000e+00, float 1.000000e+00) [[ATTR3:#.*]]
; CHECK-NEXT: [[R:%.*]] = call float @llvm.fabs.f32(float [[M]])
; CHECK-NEXT: ret float [[R]]
;

View File

@ -186,7 +186,7 @@ declare i32 @external()
define i32 @div1() {
; CHECK-LABEL: @div1(
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range !0
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), [[RNG0:!range !.*]]
; CHECK-NEXT: ret i32 0
;
%call = call i32 @external(), !range !0
@ -195,10 +195,36 @@ define i32 @div1() {
}
define i8 @sdiv_minusone_divisor() {
; CHECK-LABEL: @sdiv_minusone_divisor
; CHECK-NEXT: ret i8 poison
; CHECK-LABEL: @sdiv_minusone_divisor(
; CHECK-NEXT: ret i8 poison
;
%v = sdiv i8 -128, -1
ret i8 %v
}
; TODO: these should be poison
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 poison
;
%v = udiv i32 %x, poison
ret i32 %v
}
define i32 @poison2(i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i32 0
;
%v = udiv i32 poison, %x
ret i32 %v
}
define <2 x i32> @poison3(<2 x i32> %x) {
; CHECK-LABEL: @poison3(
; CHECK-NEXT: ret <2 x i32> undef
;
%v = udiv <2 x i32> %x, <i32 poison, i32 1>
ret <2 x i32> %v
}
!0 = !{i32 0, i32 3}

View File

@ -37,6 +37,15 @@ define i129 @vec_extract_undef_index(<3 x i129> %a) {
}
define i129 @vec_extract_poison_index(<3 x i129> %a) {
; CHECK-LABEL: @vec_extract_poison_index(
; CHECK-NEXT: ret i129 undef
;
%E1 = extractelement <3 x i129> %a, i129 poison
ret i129 %E1
}
define i129 @vec_extract_in_bounds(<3 x i129> %a) {
; CHECK-LABEL: @vec_extract_in_bounds(
; CHECK-NEXT: [[E1:%.*]] = extractelement <3 x i129> [[A:%.*]], i129 2

View File

@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; TODO: these should be poison
define i1 @poison(float %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i1 false
;
%v = fcmp oeq float %x, poison
ret i1 %v
}
define i1 @poison2(float %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i1 true
;
%v = fcmp ueq float %x, poison
ret i1 %v
}

View File

@ -526,6 +526,14 @@ define float @maxnum_undef_op1(float %x) {
ret float %val
}
define float @maxnum_poison_op1(float %x) {
; CHECK-LABEL: @maxnum_poison_op1(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.maxnum.f32(float %x, float poison)
ret float %val
}
define float @maxnum_undef_op0(float %x) {
; CHECK-LABEL: @maxnum_undef_op0(
; CHECK-NEXT: ret float [[X:%.*]]
@ -534,6 +542,14 @@ define float @maxnum_undef_op0(float %x) {
ret float %val
}
define float @maxnum_poison_op0(float %x) {
; CHECK-LABEL: @maxnum_poison_op0(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.maxnum.f32(float poison, float %x)
ret float %val
}
define float @minnum_undef_op1(float %x) {
; CHECK-LABEL: @minnum_undef_op1(
; CHECK-NEXT: ret float [[X:%.*]]
@ -542,6 +558,14 @@ define float @minnum_undef_op1(float %x) {
ret float %val
}
define float @minnum_poison_op1(float %x) {
; CHECK-LABEL: @minnum_poison_op1(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.minnum.f32(float %x, float poison)
ret float %val
}
define float @minnum_undef_op0(float %x) {
; CHECK-LABEL: @minnum_undef_op0(
; CHECK-NEXT: ret float [[X:%.*]]
@ -550,6 +574,14 @@ define float @minnum_undef_op0(float %x) {
ret float %val
}
define float @minnum_poison_op0(float %x) {
; CHECK-LABEL: @minnum_poison_op0(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.minnum.f32(float poison, float %x)
ret float %val
}
define float @minnum_undef_undef(float %x) {
; CHECK-LABEL: @minnum_undef_undef(
; CHECK-NEXT: ret float undef
@ -558,6 +590,22 @@ define float @minnum_undef_undef(float %x) {
ret float %val
}
define float @minnum_poison_undef(float %x) {
; CHECK-LABEL: @minnum_poison_undef(
; CHECK-NEXT: ret float undef
;
%val = call float @llvm.minnum.f32(float poison, float undef)
ret float %val
}
define float @minnum_undef_poison(float %x) {
; CHECK-LABEL: @minnum_undef_poison(
; CHECK-NEXT: ret float poison
;
%val = call float @llvm.minnum.f32(float undef, float poison)
ret float %val
}
define float @maxnum_undef_undef(float %x) {
; CHECK-LABEL: @maxnum_undef_undef(
; CHECK-NEXT: ret float undef
@ -566,6 +614,22 @@ define float @maxnum_undef_undef(float %x) {
ret float %val
}
define float @maxnum_poison_undef(float %x) {
; CHECK-LABEL: @maxnum_poison_undef(
; CHECK-NEXT: ret float undef
;
%val = call float @llvm.maxnum.f32(float poison, float undef)
ret float %val
}
define float @maxnum_undef_poison(float %x) {
; CHECK-LABEL: @maxnum_undef_poison(
; CHECK-NEXT: ret float poison
;
%val = call float @llvm.maxnum.f32(float undef, float poison)
ret float %val
}
define float @minnum_same_args(float %x) {
; CHECK-LABEL: @minnum_same_args(
; CHECK-NEXT: ret float [[X:%.*]]
@ -862,6 +926,14 @@ define float @maximum_undef_op1(float %x) {
ret float %val
}
define float @maximum_poison_op1(float %x) {
; CHECK-LABEL: @maximum_poison_op1(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.maximum.f32(float %x, float poison)
ret float %val
}
define float @maximum_undef_op0(float %x) {
; CHECK-LABEL: @maximum_undef_op0(
; CHECK-NEXT: ret float [[X:%.*]]
@ -870,6 +942,14 @@ define float @maximum_undef_op0(float %x) {
ret float %val
}
define float @maximum_poison_op0(float %x) {
; CHECK-LABEL: @maximum_poison_op0(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.maximum.f32(float poison, float %x)
ret float %val
}
define float @minimum_undef_op1(float %x) {
; CHECK-LABEL: @minimum_undef_op1(
; CHECK-NEXT: ret float [[X:%.*]]
@ -878,6 +958,14 @@ define float @minimum_undef_op1(float %x) {
ret float %val
}
define float @minimum_poison_op1(float %x) {
; CHECK-LABEL: @minimum_poison_op1(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.minimum.f32(float %x, float poison)
ret float %val
}
define float @minimum_undef_op0(float %x) {
; CHECK-LABEL: @minimum_undef_op0(
; CHECK-NEXT: ret float [[X:%.*]]
@ -886,6 +974,14 @@ define float @minimum_undef_op0(float %x) {
ret float %val
}
define float @minimum_poison_op0(float %x) {
; CHECK-LABEL: @minimum_poison_op0(
; CHECK-NEXT: ret float [[X:%.*]]
;
%val = call float @llvm.minimum.f32(float poison, float %x)
ret float %val
}
define float @minimum_undef_undef(float %x) {
; CHECK-LABEL: @minimum_undef_undef(
; CHECK-NEXT: ret float undef

View File

@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; TODO: the instructions with poison operands should return poison
define float @fadd_undef_op0(float %x) {
; CHECK-LABEL: @fadd_undef_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -9,6 +11,14 @@ define float @fadd_undef_op0(float %x) {
ret float %r
}
define float @fadd_poison_op0(float %x) {
; CHECK-LABEL: @fadd_poison_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd float poison, %x
ret float %r
}
define float @fadd_undef_op1(float %x) {
; CHECK-LABEL: @fadd_undef_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -17,6 +27,14 @@ define float @fadd_undef_op1(float %x) {
ret float %r
}
define float @fadd_poison_op1(float %x) {
; CHECK-LABEL: @fadd_poison_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd float %x, poison
ret float %r
}
define float @fsub_undef_op0(float %x) {
; CHECK-LABEL: @fsub_undef_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -25,6 +43,14 @@ define float @fsub_undef_op0(float %x) {
ret float %r
}
define float @fsub_poison_op0(float %x) {
; CHECK-LABEL: @fsub_poison_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub float poison, %x
ret float %r
}
define float @fsub_undef_op1(float %x) {
; CHECK-LABEL: @fsub_undef_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -33,6 +59,14 @@ define float @fsub_undef_op1(float %x) {
ret float %r
}
define float @fsub_poison_op1(float %x) {
; CHECK-LABEL: @fsub_poison_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub float %x, poison
ret float %r
}
define float @fmul_undef_op0(float %x) {
; CHECK-LABEL: @fmul_undef_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -41,6 +75,14 @@ define float @fmul_undef_op0(float %x) {
ret float %r
}
define float @fmul_poison_op0(float %x) {
; CHECK-LABEL: @fmul_poison_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul float poison, %x
ret float %r
}
define float @fmul_undef_op1(float %x) {
; CHECK-LABEL: @fmul_undef_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -49,6 +91,14 @@ define float @fmul_undef_op1(float %x) {
ret float %r
}
define float @fmul_poison_op1(float %x) {
; CHECK-LABEL: @fmul_poison_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul float %x, poison
ret float %r
}
define float @fdiv_undef_op0(float %x) {
; CHECK-LABEL: @fdiv_undef_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -57,6 +107,14 @@ define float @fdiv_undef_op0(float %x) {
ret float %r
}
define float @fdiv_poison_op0(float %x) {
; CHECK-LABEL: @fdiv_poison_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv float poison, %x
ret float %r
}
define float @fdiv_undef_op1(float %x) {
; CHECK-LABEL: @fdiv_undef_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -65,6 +123,14 @@ define float @fdiv_undef_op1(float %x) {
ret float %r
}
define float @fdiv_poison_op1(float %x) {
; CHECK-LABEL: @fdiv_poison_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv float %x, poison
ret float %r
}
define float @frem_undef_op0(float %x) {
; CHECK-LABEL: @frem_undef_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -73,6 +139,14 @@ define float @frem_undef_op0(float %x) {
ret float %r
}
define float @frem_poison_op0(float %x) {
; CHECK-LABEL: @frem_poison_op0(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem float poison, %x
ret float %r
}
define float @frem_undef_op1(float %x) {
; CHECK-LABEL: @frem_undef_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
@ -81,6 +155,14 @@ define float @frem_undef_op1(float %x) {
ret float %r
}
define float @frem_poison_op1(float %x) {
; CHECK-LABEL: @frem_poison_op1(
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem float %x, poison
ret float %r
}
; Repeat all tests with fast-math-flags. Alternate 'nnan' and 'fast' for more coverage.
define float @fadd_undef_op0_nnan(float %x) {

View File

@ -185,3 +185,13 @@ define <vscale x 2 x i64*> @ptr_idx_mix_scalar_scalable_vector() {
}
; Check ConstantExpr::getGetElementPtr() using ElementCount for size queries - end.
; TODO: this should return poison
define i8* @poison() {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i8* undef
;
%v = getelementptr i8, i8* poison, i64 1
ret i8* %v
}

View File

@ -8,8 +8,31 @@ declare void @usei8ptr(i8* %ptr)
; Ensure that we do not crash when looking at such a weird bitcast.
define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1vec, i8* %ptr2) {
; CHECK-LABEL: @bitcast_from_single_element_pointer_vector_to_pointer(
; CHECK-NEXT: [[PTR1:%.*]] = bitcast <1 x i8*> [[PTR1VEC:%.*]] to i8*
; CHECK-NEXT: call void @usei8ptr(i8* [[PTR1]])
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[PTR1]], [[PTR2:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%ptr1 = bitcast <1 x i8*> %ptr1vec to i8*
call void @usei8ptr(i8* %ptr1)
%cmp = icmp eq i8* %ptr1, %ptr2
ret i1 %cmp
}
; TODO: these should return poison
define i1 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i1 undef
;
%v = icmp eq i32 %x, poison
ret i1 %v
}
define i1 @poison2(i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i1 false
;
%v = icmp slt i32 %x, poison
ret i1 %v
}

View File

@ -42,6 +42,23 @@ define <4 x i32> @test5(<4 x i32> %A) {
ret <4 x i32> %I
}
define <4 x i32> @test5_poison(<4 x i32> %A) {
; CHECK-LABEL: @test5_poison(
; CHECK-NEXT: ret <4 x i32> undef
;
%I = insertelement <4 x i32> %A, i32 5, i64 poison
ret <4 x i32> %I
}
define <4 x i32> @elem_poison(<4 x i32> %A) {
; CHECK-LABEL: @elem_poison(
; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 poison, i32 1
; CHECK-NEXT: ret <4 x i32> [[B]]
;
%B = insertelement <4 x i32> %A, i32 poison, i32 1
ret <4 x i32> %B
}
; The undef may be replacing a poison value, so it is not safe to just return 'A'.
define <4 x i32> @PR1286(<4 x i32> %A) {

View File

@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
define {i32, i32} @poison({i32, i32} %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret { i32, i32 } [[X:%.*]]
;
%v = insertvalue {i32, i32} %x, i32 poison, 0
ret {i32, i32} %v
}
define {i32, i32} @poison2({i32, i32} %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret { i32, i32 } [[X:%.*]]
;
%elem = extractvalue {i32, i32} %x, 0
%v = insertvalue {i32, i32} poison, i32 %elem, 0
ret {i32, i32} %v
}

View File

@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; TODO: the instructions with poison operands should return poison
declare i81 @llvm.smax.i81(i81, i81)
declare i8 @llvm.smax.i8(i8, i8)
declare <2 x i8> @llvm.smax.v2i8(<2 x i8>, <2 x i8>)
@ -53,6 +55,14 @@ define i81 @smax_undef(i81 %x) {
ret i81 %r
}
define i81 @smax_poison(i81 %x) {
; CHECK-LABEL: @smax_poison(
; CHECK-NEXT: ret i81 1208925819614629174706175
;
%r = call i81 @llvm.smax.i81(i81 poison, i81 %x)
ret i81 %r
}
define i3 @smin_undef(i3 %x) {
; CHECK-LABEL: @smin_undef(
; CHECK-NEXT: ret i3 -4
@ -61,6 +71,14 @@ define i3 @smin_undef(i3 %x) {
ret i3 %r
}
define i3 @smin_poison(i3 %x) {
; CHECK-LABEL: @smin_poison(
; CHECK-NEXT: ret i3 -4
;
%r = call i3 @llvm.smin.i3(i3 %x, i3 poison)
ret i3 %r
}
define <2 x i8> @umax_undef(<2 x i8> %x) {
; CHECK-LABEL: @umax_undef(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
@ -69,6 +87,14 @@ define <2 x i8> @umax_undef(<2 x i8> %x) {
ret <2 x i8> %r
}
define <2 x i8> @umax_poison(<2 x i8> %x) {
; CHECK-LABEL: @umax_poison(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%r = call <2 x i8> @llvm.umax.v2i8(<2 x i8> poison, <2 x i8> %x)
ret <2 x i8> %r
}
define <2 x i8> @umin_undef(<2 x i8> %x) {
; CHECK-LABEL: @umin_undef(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
@ -77,6 +103,14 @@ define <2 x i8> @umin_undef(<2 x i8> %x) {
ret <2 x i8> %r
}
define <2 x i8> @umin_poison(<2 x i8> %x) {
; CHECK-LABEL: @umin_poison(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%r = call <2 x i8> @llvm.umin.v2i8(<2 x i8> %x, <2 x i8> poison)
ret <2 x i8> %r
}
define i8 @smax_maxval(i8 %x) {
; CHECK-LABEL: @smax_maxval(
; CHECK-NEXT: ret i8 127

View File

@ -42,3 +42,12 @@ define <2 x i8> @mul_by_0_vec_undef_elt(<2 x i8> %a) {
ret <2 x i8> %b
}
; TODO: this should be poison
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 0
;
%v = mul i32 %x, poison
ret i32 %v
}

View File

@ -291,3 +291,13 @@ define <2 x i1> @or_with_not_op_commute4(<2 x i1> %a, <2 x i1> %b) {
%r = or <2 x i1> %not, %a
ret <2 x i1> %r
}
; TODO: this should be poison
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 -1
;
%v = or i32 %x, poison
ret i32 %v
}

View File

@ -52,3 +52,23 @@ end:
%counter.lcssa = phi i32 [ %x, %entry ]
ret i32 %counter.lcssa
}
define i32 @poison(i1 %cond, i32 %v) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
; CHECK: A:
; CHECK-NEXT: br label [[EXIT:%.*]]
; CHECK: B:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: EXIT:
; CHECK-NEXT: ret i32 [[V:%.*]]
;
br i1 %cond, label %A, label %B
A:
br label %EXIT
B:
br label %EXIT
EXIT:
%w = phi i32 [%v, %A], [poison, %B]
ret i32 %w
}

View File

@ -236,7 +236,7 @@ declare i32 @external()
define i32 @rem4() {
; CHECK-LABEL: @rem4(
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), !range !0
; CHECK-NEXT: [[CALL:%.*]] = call i32 @external(), [[RNG0:!range !.*]]
; CHECK-NEXT: ret i32 [[CALL]]
;
%call = call i32 @external(), !range !0
@ -327,8 +327,27 @@ define <2 x i32> @srem_with_sext_bool_divisor_vec(<2 x i1> %x, <2 x i32> %y) {
}
define i8 @srem_minusone_divisor() {
; CHECK-LABEL: @srem_minusone_divisor
; CHECK-NEXT: ret i8 poison
; CHECK-LABEL: @srem_minusone_divisor(
; CHECK-NEXT: ret i8 poison
;
%v = srem i8 -128, -1
ret i8 %v
}
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 poison
;
%v = urem i32 %x, poison
ret i32 %v
}
; TODO: this should be poison
define i32 @poison2(i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i32 0
;
%v = urem i32 poison, %x
ret i32 %v
}

View File

@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
; TODO: the instructions having poison operands should be folded to poison
declare i3 @llvm.uadd.sat.i3(i3, i3)
declare i8 @llvm.uadd.sat.i8(i8, i8)
declare <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8>, <2 x i8>)
@ -86,6 +88,14 @@ define i8 @uadd_scalar_undef(i8 %a) {
ret i8 %x5
}
define i8 @uadd_scalar_poison(i8 %a) {
; CHECK-LABEL: @uadd_scalar_poison(
; CHECK-NEXT: ret i8 -1
;
%x5 = call i8 @llvm.uadd.sat.i8(i8 %a, i8 poison)
ret i8 %x5
}
define <2 x i8> @uadd_vector_undef(<2 x i8> %a) {
; CHECK-LABEL: @uadd_vector_undef(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
@ -94,6 +104,14 @@ define <2 x i8> @uadd_vector_undef(<2 x i8> %a) {
ret <2 x i8> %x5v
}
define <2 x i8> @uadd_vector_poison(<2 x i8> %a) {
; CHECK-LABEL: @uadd_vector_poison(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%x5v = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> %a, <2 x i8> <i8 poison, i8 poison>)
ret <2 x i8> %x5v
}
define i8 @uadd_scalar_undef_commute(i8 %a) {
; CHECK-LABEL: @uadd_scalar_undef_commute(
; CHECK-NEXT: ret i8 -1
@ -102,6 +120,14 @@ define i8 @uadd_scalar_undef_commute(i8 %a) {
ret i8 %x6
}
define i8 @uadd_scalar_poison_commute(i8 %a) {
; CHECK-LABEL: @uadd_scalar_poison_commute(
; CHECK-NEXT: ret i8 -1
;
%x6 = call i8 @llvm.uadd.sat.i8(i8 poison, i8 %a)
ret i8 %x6
}
define <2 x i8> @uadd_vector_undef_commute(<2 x i8> %a) {
; CHECK-LABEL: @uadd_vector_undef_commute(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
@ -110,6 +136,14 @@ define <2 x i8> @uadd_vector_undef_commute(<2 x i8> %a) {
ret <2 x i8> %x5v
}
define <2 x i8> @uadd_vector_poison_commute(<2 x i8> %a) {
; CHECK-LABEL: @uadd_vector_poison_commute(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%x5v = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> poison, <2 x i8> %a)
ret <2 x i8> %x5v
}
define i8 @sadd_scalar_0(i8 %a) {
; CHECK-LABEL: @sadd_scalar_0(
; CHECK-NEXT: ret i8 [[A:%.*]]
@ -186,6 +220,14 @@ define i8 @sadd_scalar_undef(i8 %a) {
ret i8 %y5
}
define i8 @sadd_scalar_poison(i8 %a) {
; CHECK-LABEL: @sadd_scalar_poison(
; CHECK-NEXT: ret i8 -1
;
%y5 = call i8 @llvm.sadd.sat.i8(i8 %a, i8 poison)
ret i8 %y5
}
define <2 x i8> @sadd_vector_undef(<2 x i8> %a) {
; CHECK-LABEL: @sadd_vector_undef(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
@ -194,6 +236,14 @@ define <2 x i8> @sadd_vector_undef(<2 x i8> %a) {
ret <2 x i8> %y5v
}
define <2 x i8> @sadd_vector_poison(<2 x i8> %a) {
; CHECK-LABEL: @sadd_vector_poison(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%y5v = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> %a, <2 x i8> poison)
ret <2 x i8> %y5v
}
define i8 @sadd_scalar_undef_commute(i8 %a) {
; CHECK-LABEL: @sadd_scalar_undef_commute(
; CHECK-NEXT: ret i8 -1
@ -202,6 +252,14 @@ define i8 @sadd_scalar_undef_commute(i8 %a) {
ret i8 %y6
}
define i8 @sadd_scalar_poison_commute(i8 %a) {
; CHECK-LABEL: @sadd_scalar_poison_commute(
; CHECK-NEXT: ret i8 -1
;
%y6 = call i8 @llvm.sadd.sat.i8(i8 poison, i8 %a)
ret i8 %y6
}
define <2 x i8> @sadd_vector_undef_commute(<2 x i8> %a) {
; CHECK-LABEL: @sadd_vector_undef_commute(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
@ -210,6 +268,14 @@ define <2 x i8> @sadd_vector_undef_commute(<2 x i8> %a) {
ret <2 x i8> %y6v
}
define <2 x i8> @sadd_vector_poison_commute(<2 x i8> %a) {
; CHECK-LABEL: @sadd_vector_poison_commute(
; CHECK-NEXT: ret <2 x i8> <i8 -1, i8 -1>
;
%y6v = call <2 x i8> @llvm.sadd.sat.v2i8(<2 x i8> poison, <2 x i8> %a)
ret <2 x i8> %y6v
}
define i8 @usub_scalar_0(i8 %a) {
; CHECK-LABEL: @usub_scalar_0(
; CHECK-NEXT: ret i8 [[A:%.*]]
@ -266,6 +332,14 @@ define i8 @usub_scalar_undef(i8 %a) {
ret i8 %x4
}
define i8 @usub_scalar_poison(i8 %a) {
; CHECK-LABEL: @usub_scalar_poison(
; CHECK-NEXT: ret i8 0
;
%x4 = call i8 @llvm.usub.sat.i8(i8 %a, i8 poison)
ret i8 %x4
}
define <2 x i8> @usub_vector_undef(<2 x i8> %a) {
; CHECK-LABEL: @usub_vector_undef(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
@ -274,6 +348,14 @@ define <2 x i8> @usub_vector_undef(<2 x i8> %a) {
ret <2 x i8> %x4v
}
define <2 x i8> @usub_vector_poison(<2 x i8> %a) {
; CHECK-LABEL: @usub_vector_poison(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%x4v = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> %a, <2 x i8> <i8 poison, i8 poison>)
ret <2 x i8> %x4v
}
define i8 @usub_scalar_undef_commute(i8 %a) {
; CHECK-LABEL: @usub_scalar_undef_commute(
; CHECK-NEXT: ret i8 0
@ -282,6 +364,14 @@ define i8 @usub_scalar_undef_commute(i8 %a) {
ret i8 %x5
}
define i8 @usub_scalar_poison_commute(i8 %a) {
; CHECK-LABEL: @usub_scalar_poison_commute(
; CHECK-NEXT: ret i8 0
;
%x5 = call i8 @llvm.usub.sat.i8(i8 poison, i8 %a)
ret i8 %x5
}
define <2 x i8> @usub_vector_undef_commute(<2 x i8> %a) {
; CHECK-LABEL: @usub_vector_undef_commute(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
@ -290,6 +380,14 @@ define <2 x i8> @usub_vector_undef_commute(<2 x i8> %a) {
ret <2 x i8> %x5v
}
define <2 x i8> @usub_vector_poison_commute(<2 x i8> %a) {
; CHECK-LABEL: @usub_vector_poison_commute(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%x5v = call <2 x i8> @llvm.usub.sat.v2i8(<2 x i8> <i8 poison, i8 poison>, <2 x i8> %a)
ret <2 x i8> %x5v
}
define i8 @usub_scalar_same(i8 %a) {
; CHECK-LABEL: @usub_scalar_same(
; CHECK-NEXT: ret i8 0
@ -366,6 +464,14 @@ define i8 @ssub_scalar_undef(i8 %a) {
ret i8 %y4
}
define i8 @ssub_scalar_poison(i8 %a) {
; CHECK-LABEL: @ssub_scalar_poison(
; CHECK-NEXT: ret i8 0
;
%y4 = call i8 @llvm.ssub.sat.i8(i8 %a, i8 poison)
ret i8 %y4
}
define <2 x i8> @ssub_vector_undef(<2 x i8> %a) {
; CHECK-LABEL: @ssub_vector_undef(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
@ -374,6 +480,14 @@ define <2 x i8> @ssub_vector_undef(<2 x i8> %a) {
ret <2 x i8> %y4v
}
define <2 x i8> @ssub_vector_poison(<2 x i8> %a) {
; CHECK-LABEL: @ssub_vector_poison(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%y4v = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> %a, <2 x i8> poison)
ret <2 x i8> %y4v
}
define i8 @ssub_scalar_undef_commute(i8 %a) {
; CHECK-LABEL: @ssub_scalar_undef_commute(
; CHECK-NEXT: ret i8 0
@ -382,6 +496,14 @@ define i8 @ssub_scalar_undef_commute(i8 %a) {
ret i8 %y5
}
define i8 @ssub_scalar_poison_commute(i8 %a) {
; CHECK-LABEL: @ssub_scalar_poison_commute(
; CHECK-NEXT: ret i8 0
;
%y5 = call i8 @llvm.ssub.sat.i8(i8 poison, i8 %a)
ret i8 %y5
}
define <2 x i8> @ssub_vector_undef_commute(<2 x i8> %a) {
; CHECK-LABEL: @ssub_vector_undef_commute(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
@ -390,6 +512,14 @@ define <2 x i8> @ssub_vector_undef_commute(<2 x i8> %a) {
ret <2 x i8> %y5v
}
define <2 x i8> @ssub_vector_poison_commute(<2 x i8> %a) {
; CHECK-LABEL: @ssub_vector_poison_commute(
; CHECK-NEXT: ret <2 x i8> zeroinitializer
;
%y5v = call <2 x i8> @llvm.ssub.sat.v2i8(<2 x i8> <i8 poison, i8 poison>, <2 x i8> %a)
ret <2 x i8> %y5v
}
define i8 @ssub_scalar_same(i8 %a) {
; CHECK-LABEL: @ssub_scalar_same(
; CHECK-NEXT: ret i8 0

View File

@ -968,3 +968,40 @@ define <vscale x 2 x i1> @ignore_scalable_undef(<vscale x 2 x i1> %cond) {
%s = select <vscale x 2 x i1> %cond, <vscale x 2 x i1> undef, <vscale x 2 x i1> %vec
ret <vscale x 2 x i1> %s
}
; TODO: these can be optimized more
define i32 @poison(i32 %x, i32 %y) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 [[X:%.*]]
;
%v = select i1 undef, i32 %x, i32 %y
ret i32 %v
}
define i32 @poison2(i1 %cond, i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: [[V:%.*]] = select i1 [[COND:%.*]], i32 poison, i32 [[X:%.*]]
; CHECK-NEXT: ret i32 [[V]]
;
%v = select i1 %cond, i32 poison, i32 %x
ret i32 %v
}
define i32 @poison3(i1 %cond, i32 %x) {
; CHECK-LABEL: @poison3(
; CHECK-NEXT: [[V:%.*]] = select i1 [[COND:%.*]], i32 [[X:%.*]], i32 poison
; CHECK-NEXT: ret i32 [[V]]
;
%v = select i1 %cond, i32 %x, i32 poison
ret i32 %v
}
define <2 x i32> @poison4(<2 x i1> %cond, <2 x i32> %x) {
; CHECK-LABEL: @poison4(
; CHECK-NEXT: [[V:%.*]] = select <2 x i1> [[COND:%.*]], <2 x i32> [[X:%.*]], <2 x i32> poison
; CHECK-NEXT: ret <2 x i32> [[V]]
;
%v = select <2 x i1> %cond, <2 x i32> %x, <2 x i32> poison
ret <2 x i32> %v
}

View File

@ -237,3 +237,53 @@ define <2 x i64> @shl_or_shr2v(<2 x i32> %a, <2 x i32> %b) {
%tmp5 = lshr <2 x i64> %tmp4, <i64 31, i64 31>
ret <2 x i64> %tmp5
}
; TOOD: these should be poison
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 undef
;
%v = lshr i32 %x, poison
ret i32 %v
}
define i32 @poison2(i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i32 undef
;
%v = ashr i32 %x, poison
ret i32 %v
}
define i32 @poison3(i32 %x) {
; CHECK-LABEL: @poison3(
; CHECK-NEXT: ret i32 undef
;
%v = shl i32 %x, poison
ret i32 %v
}
define i32 @poison4(i32 %x) {
; CHECK-LABEL: @poison4(
; CHECK-NEXT: ret i32 0
;
%v = lshr i32 poison, %x
ret i32 %v
}
define i32 @poison5(i32 %x) {
; CHECK-LABEL: @poison5(
; CHECK-NEXT: ret i32 0
;
%v = ashr i32 poison, %x
ret i32 %v
}
define i32 @poison6(i32 %x) {
; CHECK-LABEL: @poison6(
; CHECK-NEXT: ret i32 0
;
%v = shl i32 poison, %x
ret i32 %v
}

View File

@ -36,6 +36,16 @@ define <4 x i32> @splat_operand(<4 x i32> %x) {
ret <4 x i32> %shuf
}
define <4 x i32> @splat_operand_poison(<4 x i32> %x) {
; CHECK-LABEL: @splat_operand_poison(
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
;
%splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
%shuf = shufflevector <4 x i32> %splat, <4 x i32> poison, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
ret <4 x i32> %shuf
}
define <4 x i32> @splat_operand1(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @splat_operand1(
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]], <4 x i32> zeroinitializer

View File

@ -51,3 +51,20 @@ define <2 x i32> @neg_neg_vec(<2 x i32> %A) {
ret <2 x i32> %C
}
; TODO: these should be poison
define i32 @poison1(i32 %x) {
; CHECK-LABEL: @poison1(
; CHECK-NEXT: ret i32 undef
;
%v = sub i32 %x, poison
ret i32 %v
}
define i32 @poison2(i32 %x) {
; CHECK-LABEL: @poison2(
; CHECK-NEXT: ret i32 undef
;
%v = sub i32 poison, %x
ret i32 %v
}

View File

@ -0,0 +1,10 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
define i32 @poison(i32 %x) {
; CHECK-LABEL: @poison(
; CHECK-NEXT: ret i32 poison
;
%v = xor i32 %x, poison
ret i32 %v
}