summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-03-10 16:51:28 +0000
committerSanjay Patel <spatel@rotateright.com>2018-03-10 16:51:28 +0000
commit42227168220a642afe0e412595e5a7f6244f9b3f (patch)
tree15e40ddcf87f2dac3ec233782865daf53570bae5 /llvm/lib/Analysis
parent3b36bb036297e5a603153331665e74faac56c632 (diff)
downloadbcm5719-llvm-42227168220a642afe0e412595e5a7f6244f9b3f.tar.gz
bcm5719-llvm-42227168220a642afe0e412595e5a7f6244f9b3f.zip
[InstSimplify] fp_binop X, undef --> NaN
The variable operand could be NaN, so it's always safe to propagate NaN. llvm-svn: 327212
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 8b8a0417aa6..a95a775ead6 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4156,6 +4156,9 @@ static Value *SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
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;
@@ -4190,6 +4193,9 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
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;
@@ -4222,6 +4228,9 @@ static Value *SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
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;
@@ -4260,13 +4269,8 @@ static Value *SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
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()))
@@ -4312,13 +4316,8 @@ static Value *SimplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
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
OpenPOWER on IntegriCloud