forked from OSchip/llvm-project
				
			[InstSimplify] Fold nnan/ninf violation to poison
As the comment already indicates, performing an operation with nnan/ninf flags on a nan/inf or undef results in poison. Now that we have a proper poison value, we no longer need to relax it to undef.
This commit is contained in:
		
							parent
							
								
									edb52c626b
								
							
						
					
					
						commit
						3715c99be9
					
				| 
						 | 
					@ -4781,11 +4781,11 @@ static Constant *simplifyFPOp(ArrayRef<Value *> Ops,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If this operation has 'nnan' or 'ninf' and at least 1 disallowed operand
 | 
					    // If this operation has 'nnan' or 'ninf' and at least 1 disallowed operand
 | 
				
			||||||
    // (an undef operand can be chosen to be Nan/Inf), then the result of
 | 
					    // (an undef operand can be chosen to be Nan/Inf), then the result of
 | 
				
			||||||
    // this operation is poison. That result can be relaxed to undef.
 | 
					    // this operation is poison.
 | 
				
			||||||
    if (FMF.noNaNs() && (IsNan || IsUndef))
 | 
					    if (FMF.noNaNs() && (IsNan || IsUndef))
 | 
				
			||||||
      return UndefValue::get(V->getType());
 | 
					      return PoisonValue::get(V->getType());
 | 
				
			||||||
    if (FMF.noInfs() && (IsInf || IsUndef))
 | 
					    if (FMF.noInfs() && (IsInf || IsUndef))
 | 
				
			||||||
      return UndefValue::get(V->getType());
 | 
					      return PoisonValue::get(V->getType());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (IsUndef || IsNan)
 | 
					    if (IsUndef || IsNan)
 | 
				
			||||||
      return propagateNaN(cast<Constant>(V));
 | 
					      return propagateNaN(cast<Constant>(V));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,7 @@ define <2 x double> @unary_fneg_nan_2(<2 x double> %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fadd_nan_op0_nnan(float %x) {
 | 
					define float @fadd_nan_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fadd_nan_op0_nnan(
 | 
					; CHECK-LABEL: @fadd_nan_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fadd nnan float 0x7FF8000000000000, %x
 | 
					  %r = fadd nnan float 0x7FF8000000000000, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -145,7 +145,7 @@ define float @fadd_nan_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fadd_nan_op1_fast(float %x) {
 | 
					define float @fadd_nan_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fadd_nan_op1_fast(
 | 
					; CHECK-LABEL: @fadd_nan_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fadd fast float %x, 0x7FF8000000000000
 | 
					  %r = fadd fast float %x, 0x7FF8000000000000
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -153,7 +153,7 @@ define float @fadd_nan_op1_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fsub_nan_op0_fast(float %x) {
 | 
					define float @fsub_nan_op0_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fsub_nan_op0_fast(
 | 
					; CHECK-LABEL: @fsub_nan_op0_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fsub fast float 0x7FF8000000000000, %x
 | 
					  %r = fsub fast float 0x7FF8000000000000, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -161,7 +161,7 @@ define float @fsub_nan_op0_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fsub_nan_op1_nnan(float %x) {
 | 
					define float @fsub_nan_op1_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fsub_nan_op1_nnan(
 | 
					; CHECK-LABEL: @fsub_nan_op1_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fsub nnan float %x, 0x7FF8000000000000
 | 
					  %r = fsub nnan float %x, 0x7FF8000000000000
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -169,7 +169,7 @@ define float @fsub_nan_op1_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fmul_nan_op0_nnan(float %x) {
 | 
					define float @fmul_nan_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fmul_nan_op0_nnan(
 | 
					; CHECK-LABEL: @fmul_nan_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fmul nnan float 0x7FF8000000000000, %x
 | 
					  %r = fmul nnan float 0x7FF8000000000000, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -177,7 +177,7 @@ define float @fmul_nan_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fmul_nan_op1_fast(float %x) {
 | 
					define float @fmul_nan_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fmul_nan_op1_fast(
 | 
					; CHECK-LABEL: @fmul_nan_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fmul fast float %x, 0x7FF8000000000000
 | 
					  %r = fmul fast float %x, 0x7FF8000000000000
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -185,7 +185,7 @@ define float @fmul_nan_op1_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fdiv_nan_op0_fast(float %x) {
 | 
					define float @fdiv_nan_op0_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fdiv_nan_op0_fast(
 | 
					; CHECK-LABEL: @fdiv_nan_op0_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fdiv fast float 0x7FF8000000000000, %x
 | 
					  %r = fdiv fast float 0x7FF8000000000000, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -193,7 +193,7 @@ define float @fdiv_nan_op0_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fdiv_nan_op1_nnan(float %x) {
 | 
					define float @fdiv_nan_op1_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fdiv_nan_op1_nnan(
 | 
					; CHECK-LABEL: @fdiv_nan_op1_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fdiv nnan float %x, 0x7FF8000000000000
 | 
					  %r = fdiv nnan float %x, 0x7FF8000000000000
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -201,7 +201,7 @@ define float @fdiv_nan_op1_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @frem_nan_op0_nnan(float %x) {
 | 
					define float @frem_nan_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @frem_nan_op0_nnan(
 | 
					; CHECK-LABEL: @frem_nan_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = frem nnan float 0x7FF8000000000000, %x
 | 
					  %r = frem nnan float 0x7FF8000000000000, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -209,7 +209,7 @@ define float @frem_nan_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @frem_nan_op1_fast(float %x) {
 | 
					define float @frem_nan_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @frem_nan_op1_fast(
 | 
					; CHECK-LABEL: @frem_nan_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = frem fast float %x, 0x7FF8000000000000
 | 
					  %r = frem fast float %x, 0x7FF8000000000000
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ define float @frem_poison_op1(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fadd_undef_op0_nnan(float %x) {
 | 
					define float @fadd_undef_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fadd_undef_op0_nnan(
 | 
					; CHECK-LABEL: @fadd_undef_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fadd nnan float undef, %x
 | 
					  %r = fadd nnan float undef, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -175,7 +175,7 @@ define float @fadd_undef_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fadd_undef_op1_fast(float %x) {
 | 
					define float @fadd_undef_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fadd_undef_op1_fast(
 | 
					; CHECK-LABEL: @fadd_undef_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fadd fast float %x, undef
 | 
					  %r = fadd fast float %x, undef
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,7 @@ define float @fadd_undef_op1_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fsub_undef_op0_fast(float %x) {
 | 
					define float @fsub_undef_op0_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fsub_undef_op0_fast(
 | 
					; CHECK-LABEL: @fsub_undef_op0_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fsub fast float undef, %x
 | 
					  %r = fsub fast float undef, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -191,7 +191,7 @@ define float @fsub_undef_op0_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fsub_undef_op1_nnan(float %x) {
 | 
					define float @fsub_undef_op1_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fsub_undef_op1_nnan(
 | 
					; CHECK-LABEL: @fsub_undef_op1_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fsub nnan float %x, undef
 | 
					  %r = fsub nnan float %x, undef
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -199,7 +199,7 @@ define float @fsub_undef_op1_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fmul_undef_op0_nnan(float %x) {
 | 
					define float @fmul_undef_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fmul_undef_op0_nnan(
 | 
					; CHECK-LABEL: @fmul_undef_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fmul nnan float undef, %x
 | 
					  %r = fmul nnan float undef, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -207,7 +207,7 @@ define float @fmul_undef_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fmul_undef_op1_fast(float %x) {
 | 
					define float @fmul_undef_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fmul_undef_op1_fast(
 | 
					; CHECK-LABEL: @fmul_undef_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fmul fast float %x, undef
 | 
					  %r = fmul fast float %x, undef
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -215,7 +215,7 @@ define float @fmul_undef_op1_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fdiv_undef_op0_fast(float %x) {
 | 
					define float @fdiv_undef_op0_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fdiv_undef_op0_fast(
 | 
					; CHECK-LABEL: @fdiv_undef_op0_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fdiv fast float undef, %x
 | 
					  %r = fdiv fast float undef, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -223,7 +223,7 @@ define float @fdiv_undef_op0_fast(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @fdiv_undef_op1_nnan(float %x) {
 | 
					define float @fdiv_undef_op1_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @fdiv_undef_op1_nnan(
 | 
					; CHECK-LABEL: @fdiv_undef_op1_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fdiv nnan float %x, undef
 | 
					  %r = fdiv nnan float %x, undef
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -231,7 +231,7 @@ define float @fdiv_undef_op1_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @frem_undef_op0_nnan(float %x) {
 | 
					define float @frem_undef_op0_nnan(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @frem_undef_op0_nnan(
 | 
					; CHECK-LABEL: @frem_undef_op0_nnan(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = frem nnan float undef, %x
 | 
					  %r = frem nnan float undef, %x
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -239,7 +239,7 @@ define float @frem_undef_op0_nnan(float %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define float @frem_undef_op1_fast(float %x) {
 | 
					define float @frem_undef_op1_fast(float %x) {
 | 
				
			||||||
; CHECK-LABEL: @frem_undef_op1_fast(
 | 
					; CHECK-LABEL: @frem_undef_op1_fast(
 | 
				
			||||||
; CHECK-NEXT:    ret float undef
 | 
					; CHECK-NEXT:    ret float poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = frem fast float %x, undef
 | 
					  %r = frem fast float %x, undef
 | 
				
			||||||
  ret float %r
 | 
					  ret float %r
 | 
				
			||||||
| 
						 | 
					@ -263,7 +263,7 @@ define double @fadd_ninf_nan_op1(double %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define double @fdiv_ninf_inf_op0(double %x) {
 | 
					define double @fdiv_ninf_inf_op0(double %x) {
 | 
				
			||||||
; CHECK-LABEL: @fdiv_ninf_inf_op0(
 | 
					; CHECK-LABEL: @fdiv_ninf_inf_op0(
 | 
				
			||||||
; CHECK-NEXT:    ret double undef
 | 
					; CHECK-NEXT:    ret double poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fdiv ninf double 0x7ff0000000000000, %x
 | 
					  %r = fdiv ninf double 0x7ff0000000000000, %x
 | 
				
			||||||
  ret double %r
 | 
					  ret double %r
 | 
				
			||||||
| 
						 | 
					@ -271,7 +271,7 @@ define double @fdiv_ninf_inf_op0(double %x) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define double @fadd_ninf_inf_op1(double %x) {
 | 
					define double @fadd_ninf_inf_op1(double %x) {
 | 
				
			||||||
; CHECK-LABEL: @fadd_ninf_inf_op1(
 | 
					; CHECK-LABEL: @fadd_ninf_inf_op1(
 | 
				
			||||||
; CHECK-NEXT:    ret double undef
 | 
					; CHECK-NEXT:    ret double poison
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
  %r = fadd ninf double %x, 0xfff0000000000000
 | 
					  %r = fadd ninf double %x, 0xfff0000000000000
 | 
				
			||||||
  ret double %r
 | 
					  ret double %r
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue