[PATCH] D85709: [InstSimplify] Implement Instruction simplification for X/sqrt(X) to sqrt(X).

Venkataramanan Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 00:17:10 PDT 2020


venkataramanan.kumar.llvm updated this revision to Diff 284591.
venkataramanan.kumar.llvm added a comment.

Fixed test case to check for proper return value.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85709/new/

https://reviews.llvm.org/D85709

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
@@ -26,6 +26,17 @@
   ret double %d
 }
 
+declare double @llvm.sqrt.f64(double) #1
+define double @sqrt_fdiv_common_operand(double %x) {
+; CHECK-LABEL: @sqrt_fdiv_common_operand(
+; CHECK-NEXT:    %1 = tail call fast double @llvm.sqrt.f64(double %x)
+; CHECK-NEXT:    ret double %1
+;
+  %1 = tail call fast double @llvm.sqrt.f64(double %x)
+  %2 = fdiv reassoc nnan fast double %x, %1
+  ret double %1
+}
+
 ; Negative test - the fdiv must be reassociative and not allow NaNs.
 
 define double @fmul_fdiv_common_operand_too_strict(double %x, double %y) {
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4890,6 +4890,11 @@
       return ConstantFP::get(Op0->getType(), -1.0);
   }
 
+  // X/sqrt(X)  = sqrt(X)
+  if (match(Op1, m_Intrinsic<Intrinsic::sqrt>(m_Specific(Op0))) &&
+      FMF.allowReassoc() && FMF.noNaNs() && FMF.noSignedZeros())
+    return Op1;
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85709.284591.patch
Type: text/x-patch
Size: 1262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200811/a01e9f4b/attachment.bin>


More information about the llvm-commits mailing list