-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NVPTX] Lower -1/x to neg.f64(rcp.rn.f64) instead of fdiv (#98343)
The NVPTX backend lowers 1/x to rcp.rn.f64 instruction instead of slower fdiv instruction. However, in the case of -1/x, it uses the slower fdiv instruction. After this change, -1/x will be lowered into neg.f64 (rcp.rn.f64).
- Loading branch information
1 parent
331ba43
commit 3a0e015
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -march=nvptx64 | FileCheck %s | ||
; RUN: %if ptxas %{ llc < %s -march=nvptx64 | %ptxas-verify %} | ||
|
||
target triple = "nvptx64-nvidia-cuda" | ||
|
||
;; Check if fneg (fdiv 1, X) lowers to fneg (rcp.rn X). | ||
|
||
define double @test1(double %in) { | ||
; CHECK-LABEL: test1( | ||
; CHECK: { | ||
; CHECK-NEXT: .reg .f64 %fd<4>; | ||
; CHECK-EMPTY: | ||
; CHECK-NEXT: // %bb.0: | ||
; CHECK-NEXT: ld.param.f64 %fd1, [test1_param_0]; | ||
; CHECK-NEXT: rcp.rn.f64 %fd2, %fd1; | ||
; CHECK-NEXT: neg.f64 %fd3, %fd2; | ||
; CHECK-NEXT: st.param.f64 [func_retval0+0], %fd3; | ||
; CHECK-NEXT: ret; | ||
%div = fdiv double 1.000000e+00, %in | ||
%neg = fsub double -0.000000e+00, %div | ||
ret double %neg | ||
} | ||
|
||
;; Check if fdiv -1, X lowers to fneg (rcp.rn X). | ||
|
||
define double @test2(double %in) { | ||
; CHECK-LABEL: test2( | ||
; CHECK: { | ||
; CHECK-NEXT: .reg .f64 %fd<4>; | ||
; CHECK-EMPTY: | ||
; CHECK-NEXT: // %bb.0: | ||
; CHECK-NEXT: ld.param.f64 %fd1, [test2_param_0]; | ||
; CHECK-NEXT: rcp.rn.f64 %fd2, %fd1; | ||
; CHECK-NEXT: neg.f64 %fd3, %fd2; | ||
; CHECK-NEXT: st.param.f64 [func_retval0+0], %fd3; | ||
; CHECK-NEXT: ret; | ||
%div = fdiv double -1.000000e+00, %in | ||
ret double %div | ||
} | ||
|
||
;; Check if fdiv 1, (fneg X) lowers to fneg (rcp.rn X). | ||
|
||
define double @test3(double %in) { | ||
; CHECK-LABEL: test3( | ||
; CHECK: { | ||
; CHECK-NEXT: .reg .f64 %fd<4>; | ||
; CHECK-EMPTY: | ||
; CHECK-NEXT: // %bb.0: | ||
; CHECK-NEXT: ld.param.f64 %fd1, [test3_param_0]; | ||
; CHECK-NEXT: rcp.rn.f64 %fd2, %fd1; | ||
; CHECK-NEXT: neg.f64 %fd3, %fd2; | ||
; CHECK-NEXT: st.param.f64 [func_retval0+0], %fd3; | ||
; CHECK-NEXT: ret; | ||
%neg = fsub double -0.000000e+00, %in | ||
%div = fdiv double 1.000000e+00, %neg | ||
ret double %div | ||
} |