if (Constant *C = foldOrCommuteConstant(Instruction::FAdd, Op0, Op1, Q))
return C;
+ if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ return ConstantFP::getNaN(Op0->getType());
+
// fadd X, -0 ==> X
if (match(Op1, m_NegZero()))
return Op0;
if (Constant *C = foldOrCommuteConstant(Instruction::FSub, Op0, Op1, Q))
return C;
+ if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ return ConstantFP::getNaN(Op0->getType());
+
// fsub X, 0 ==> X
if (match(Op1, m_Zero()))
return Op0;
if (Constant *C = foldOrCommuteConstant(Instruction::FMul, Op0, Op1, Q))
return C;
+ if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ return ConstantFP::getNaN(Op0->getType());
+
// fmul X, 1.0 ==> X
if (match(Op1, m_FPOne()))
return Op0;
if (Constant *C = foldOrCommuteConstant(Instruction::FDiv, Op0, Op1, Q))
return C;
- // undef / X -> undef (the undef could be a snan).
- if (match(Op0, m_Undef()))
- return Op0;
-
- // X / undef -> undef
- if (match(Op1, m_Undef()))
- return Op1;
+ if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ return ConstantFP::getNaN(Op0->getType());
// X / 1.0 -> X
if (match(Op1, m_FPOne()))
if (Constant *C = foldOrCommuteConstant(Instruction::FRem, Op0, Op1, Q))
return C;
- // undef % X -> undef (the undef could be a snan).
- if (match(Op0, m_Undef()))
- return Op0;
-
- // X % undef -> undef
- if (match(Op1, m_Undef()))
- return Op1;
+ if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
+ return ConstantFP::getNaN(Op0->getType());
// 0 % X -> 0
// Requires that NaNs are off (X could be zero) and signed zeroes are
define float @fadd_undef_op0(float %x) {
; CHECK-LABEL: @fadd_undef_op0(
-; CHECK-NEXT: [[R:%.*]] = fadd float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd float undef, %x
ret float %r
define float @fadd_undef_op1(float %x) {
; CHECK-LABEL: @fadd_undef_op1(
-; CHECK-NEXT: [[R:%.*]] = fadd float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd float %x, undef
ret float %r
define float @fsub_undef_op0(float %x) {
; CHECK-LABEL: @fsub_undef_op0(
-; CHECK-NEXT: [[R:%.*]] = fsub float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub float undef, %x
ret float %r
define float @fsub_undef_op1(float %x) {
; CHECK-LABEL: @fsub_undef_op1(
-; CHECK-NEXT: [[R:%.*]] = fsub float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub float %x, undef
ret float %r
define float @fmul_undef_op0(float %x) {
; CHECK-LABEL: @fmul_undef_op0(
-; CHECK-NEXT: [[R:%.*]] = fmul float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul float undef, %x
ret float %r
define float @fmul_undef_op1(float %x) {
; CHECK-LABEL: @fmul_undef_op1(
-; CHECK-NEXT: [[R:%.*]] = fmul float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul float %x, undef
ret float %r
define float @fdiv_undef_op0(float %x) {
; CHECK-LABEL: @fdiv_undef_op0(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv float undef, %x
ret float %r
define float @fdiv_undef_op1(float %x) {
; CHECK-LABEL: @fdiv_undef_op1(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv float %x, undef
ret float %r
define float @frem_undef_op0(float %x) {
; CHECK-LABEL: @frem_undef_op0(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem float undef, %x
ret float %r
define float @frem_undef_op1(float %x) {
; CHECK-LABEL: @frem_undef_op1(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem float %x, undef
ret float %r
define float @fadd_undef_op0_nnan(float %x) {
; CHECK-LABEL: @fadd_undef_op0_nnan(
-; CHECK-NEXT: [[R:%.*]] = fadd nnan float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd nnan float undef, %x
ret float %r
define float @fadd_undef_op1_fast(float %x) {
; CHECK-LABEL: @fadd_undef_op1_fast(
-; CHECK-NEXT: [[R:%.*]] = fadd fast float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fadd fast float %x, undef
ret float %r
define float @fsub_undef_op0_fast(float %x) {
; CHECK-LABEL: @fsub_undef_op0_fast(
-; CHECK-NEXT: [[R:%.*]] = fsub fast float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub fast float undef, %x
ret float %r
define float @fsub_undef_op1_nnan(float %x) {
; CHECK-LABEL: @fsub_undef_op1_nnan(
-; CHECK-NEXT: [[R:%.*]] = fsub nnan float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fsub nnan float %x, undef
ret float %r
define float @fmul_undef_op0_nnan(float %x) {
; CHECK-LABEL: @fmul_undef_op0_nnan(
-; CHECK-NEXT: [[R:%.*]] = fmul nnan float undef, [[X:%.*]]
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul nnan float undef, %x
ret float %r
define float @fmul_undef_op1_fast(float %x) {
; CHECK-LABEL: @fmul_undef_op1_fast(
-; CHECK-NEXT: [[R:%.*]] = fmul fast float [[X:%.*]], undef
-; CHECK-NEXT: ret float [[R]]
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fmul fast float %x, undef
ret float %r
define float @fdiv_undef_op0_fast(float %x) {
; CHECK-LABEL: @fdiv_undef_op0_fast(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv fast float undef, %x
ret float %r
define float @fdiv_undef_op1_nnan(float %x) {
; CHECK-LABEL: @fdiv_undef_op1_nnan(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = fdiv nnan float %x, undef
ret float %r
define float @frem_undef_op0_nnan(float %x) {
; CHECK-LABEL: @frem_undef_op0_nnan(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem nnan float undef, %x
ret float %r
define float @frem_undef_op1_fast(float %x) {
; CHECK-LABEL: @frem_undef_op1_fast(
-; CHECK-NEXT: ret float undef
+; CHECK-NEXT: ret float 0x7FF8000000000000
;
%r = frem fast float %x, undef
ret float %r