[PATCH] D74713: [ConstantFold] fold fsub -0.0, undef to undef rather than NaN
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 14:02:40 PST 2020
spatel updated this revision to Diff 245734.
spatel retitled this revision from "[ConstantFold] fold most FP ops with undef operand to undef rather than NaN" to "[ConstantFold] fold fsub -0.0, undef to undef rather than NaN".
spatel added a comment.
Patch updated:
Only handle the fneg-like form of fsub.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D74713/new/
https://reviews.llvm.org/D74713
Files:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Analysis/ConstantFolding/fp-undef.ll
Index: llvm/test/Analysis/ConstantFolding/fp-undef.ll
===================================================================
--- llvm/test/Analysis/ConstantFolding/fp-undef.ll
+++ llvm/test/Analysis/ConstantFolding/fp-undef.ll
@@ -235,7 +235,7 @@
define double @fsub_undef_op1_constant_neg0(double %x) {
; CHECK-LABEL: @fsub_undef_op1_constant_neg0(
-; CHECK-NEXT: ret double 0x7FF8000000000000
+; CHECK-NEXT: ret double undef
;
%r = fsub double 0x8000000000000000, undef
ret double %r
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -1116,8 +1116,12 @@
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74713.245734.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200220/d5a1fb05/attachment.bin>
More information about the llvm-commits
mailing list