[PATCH] D136096: InstSimplify: Fold fdiv nnan ninf x, 0 -> poison

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 17 11:17:04 PDT 2022


arsenm created this revision.
arsenm added reviewers: spatel, cameron.mcinally, kpn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D136096

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/fdiv.ll


Index: llvm/test/Transforms/InstSimplify/fdiv.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/fdiv.ll
+++ llvm/test/Transforms/InstSimplify/fdiv.ll
@@ -64,8 +64,7 @@
 ; https://alive2.llvm.org/ce/z/ryZBn6
 define float @fdiv_nnan_ninf_by_zero_f32(float %x) {
 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_f32(
-; CHECK-NEXT:    [[FDIV:%.*]] = fdiv nnan ninf float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT:    ret float [[FDIV]]
+; CHECK-NEXT:    ret float poison
 ;
   %fdiv = fdiv nnan ninf float %x, 0.0
   ret float %fdiv
@@ -73,8 +72,7 @@
 
 define float @fdiv_nnan_ninf_by_negzero_f32(float %x) {
 ; CHECK-LABEL: @fdiv_nnan_ninf_by_negzero_f32(
-; CHECK-NEXT:    [[FDIV:%.*]] = fdiv nnan ninf float [[X:%.*]], -0.000000e+00
-; CHECK-NEXT:    ret float [[FDIV]]
+; CHECK-NEXT:    ret float poison
 ;
   %fdiv = fdiv nnan ninf float %x, -0.0
   ret float %fdiv
@@ -98,8 +96,7 @@
 
 define <2 x float> @fdiv_nnan_ninf_by_zero_v2f32(<2 x float> %x) {
 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_v2f32(
-; CHECK-NEXT:    [[FDIV:%.*]] = fdiv nnan ninf <2 x float> [[X:%.*]], zeroinitializer
-; CHECK-NEXT:    ret <2 x float> [[FDIV]]
+; CHECK-NEXT:    ret <2 x float> poison
 ;
   %fdiv = fdiv nnan ninf <2 x float> %x, zeroinitializer
   ret <2 x float> %fdiv
@@ -115,8 +112,7 @@
 
 define <2 x float> @fdiv_nnan_ninf_by_zero_undef_v2f32(<2 x float> %x) {
 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_undef_v2f32(
-; CHECK-NEXT:    [[FDIV:%.*]] = fdiv nnan ninf <2 x float> [[X:%.*]], <float 0.000000e+00, float undef>
-; CHECK-NEXT:    ret <2 x float> [[FDIV]]
+; CHECK-NEXT:    ret <2 x float> poison
 ;
   %fdiv = fdiv nnan ninf <2 x float> %x, <float 0.0, float undef>
   ret <2 x float> %fdiv
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5444,6 +5444,10 @@
     if (match(Op0, m_FNegNSZ(m_Specific(Op1))) ||
         match(Op1, m_FNegNSZ(m_Specific(Op0))))
       return ConstantFP::get(Op0->getType(), -1.0);
+
+    // nnan ninf X / 0.0 -> poison
+    if (FMF.noInfs() && match(Op1, m_AnyZeroFP()))
+      return PoisonValue::get(Op1->getType());
   }
 
   return nullptr;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136096.468262.patch
Type: text/x-patch
Size: 2290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221017/ccc65d92/attachment.bin>


More information about the llvm-commits mailing list