[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
Fri Feb 21 05:21:01 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd799190851fd: [ConstantFold] fold fsub -0.0, undef to undef rather than NaN (authored by spatel).

Repository:
  rG LLVM Github Monorepo

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.245825.patch
Type: text/x-patch
Size: 1135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200221/2fb58231/attachment.bin>


More information about the llvm-commits mailing list