[llvm] [NVPTX] Lower -1/x to neg.f64(recp.rn.f64) instead of fdiv (PR #98343)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 10:04:48 PDT 2024


================
@@ -0,0 +1,13 @@
+; RUN: llc < %s -march=nvptx64 | FileCheck %s
+; RUN: %if ptxas %{ llc < %s -march=nvptx64 | %ptxas-verify %}
+
+;; Check if fdiv -1, X lowers to fneg (rcp.rn X).
+
+; CHECK-LABEL: .func{{.*}}test1
+define double @test1(double %in) {
+; CHECK: rcp.rn.f64 [[RCP:%.*]], [[X:%.*]];
+; CHECK-NEXT: neg.f64 [[FNEG:%.*]], [[RCP]];
+  %div = fdiv double 1.000000e+00, %in
+  %neg = fsub double -0.000000e+00, %div
+  ret double %neg
+}
----------------
gonzalobg wrote:

It looks like this test is doing `-0. - 1./x`, but the comment says it is intended to test `-1. / x`. 
Would it make sense to add a `@test2` that also checks the following:

```suggestion
}

; CHECK-LABEL: .func{{.*}}test2
define double @test2(double %in) {
; CHECK: rcp.rn.f64 [[RCP:%.*]], [[X:%.*]];
; CHECK-NEXT: neg.f64 [[FNEG:%.*]], [[RCP]];
  %res = fdiv double -1.000000e+00, %in
  ret double %res
}
```

?

https://github.com/llvm/llvm-project/pull/98343


More information about the llvm-commits mailing list