diff options
author | Sanjay Patel <spatel@rotateright.com> | 2020-02-21 07:58:36 -0500 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2020-02-21 08:03:19 -0500 |
commit | d799190851fdd94800428ba335f864ce5fd8135b (patch) | |
tree | 5de0d299a4f8e0b8d8bce0b2c3b07b5c1d86abf3 /llvm/lib/IR/ConstantFold.cpp | |
parent | 99b03c1c18de3e4228e31ef04d38f2d530d335be (diff) | |
download | llvm-d799190851fdd94800428ba335f864ce5fd8135b.zip llvm-d799190851fdd94800428ba335f864ce5fd8135b.tar.gz llvm-d799190851fdd94800428ba335f864ce5fd8135b.tar.bz2 |
[ConstantFold] fold fsub -0.0, undef to undef rather than NaN
A question about this behavior came up on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2020-February/139003.html
...and as part of backend improvements in D73978, but this is an IR
change first because we already have fairly thorough tests in place
here.
We decided not to implement a more general change that would have
folded any FP binop with nearly arbitrary constant + undef operand
to undef because that is not theoretically correct (even if it is
practically correct).
Differential Revision: https://reviews.llvm.org/D74713
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index ef679fb..acd10b4 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1116,8 +1116,12 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, return C1; // undef << X -> 0 return Constant::getNullValue(C1->getType()); - case Instruction::FAdd: case Instruction::FSub: + // -0.0 - undef --> undef (consistent with "fneg undef") + if (match(C1, m_NegZeroFP()) && isa<UndefValue>(C2)) + return C2; + LLVM_FALLTHROUGH; + case Instruction::FAdd: case Instruction::FMul: case Instruction::FDiv: case Instruction::FRem: |