]> granicus.if.org Git - llvm/commitdiff
[NVPTX] Enable combineRepeatedFPDivisors for NVPTX.
authorJustin Lebar <jlebar@google.com>
Fri, 3 Feb 2017 15:13:50 +0000 (15:13 +0000)
committerJustin Lebar <jlebar@google.com>
Fri, 3 Feb 2017 15:13:50 +0000 (15:13 +0000)
Reviewers: tra

Subscribers: jholewinski, llvm-commits

Differential Revision: https://reviews.llvm.org/D29477

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294011 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/NVPTX/NVPTXISelLowering.h
test/CodeGen/NVPTX/fast-math.ll

index f6494f6d37ef2bdc26fe7114b48d2236d13b3121..ab78d8a936b30c64039274226afbb410f60490cf 100644 (file)
@@ -530,6 +530,8 @@ public:
                           int &ExtraSteps, bool &UseOneConst,
                           bool Reciprocal) const override;
 
+  unsigned combineRepeatedFPDivisors() const override { return 2; }
+
   bool allowFMA(MachineFunction &MF, CodeGenOpt::Level OptLevel) const;
   bool allowUnsafeFPMath(MachineFunction &MF) const;
 
index f925d67434c8c93cbb5333b1b9eb5de26b61016c..56b1f88f3b2eaf99a35c2e0fdee43063d88117e9 100644 (file)
@@ -117,5 +117,49 @@ define float @fcos_approx(float %a) #0 {
   ret float %r
 }
 
+; CHECK-LABEL: repeated_div_recip_allowed
+define float @repeated_div_recip_allowed(i1 %pred, float %a, float %b, float %divisor) {
+; CHECK: rcp.rn.f32
+; CHECK: mul.rn.f32
+; CHECK: mul.rn.f32
+  %x = fdiv arcp float %a, %divisor
+  %y = fdiv arcp float %b, %divisor
+  %z = select i1 %pred, float %x, float %y
+  ret float %z
+}
+
+; CHECK-LABEL: repeated_div_recip_allowed_ftz
+define float @repeated_div_recip_allowed_ftz(i1 %pred, float %a, float %b, float %divisor) #1 {
+; CHECK: rcp.rn.ftz.f32
+; CHECK: mul.rn.ftz.f32
+; CHECK: mul.rn.ftz.f32
+  %x = fdiv arcp float %a, %divisor
+  %y = fdiv arcp float %b, %divisor
+  %z = select i1 %pred, float %x, float %y
+  ret float %z
+}
+
+; CHECK-LABEL: repeated_div_fast
+define float @repeated_div_fast(i1 %pred, float %a, float %b, float %divisor) #0 {
+; CHECK: rcp.approx.f32
+; CHECK: mul.f32
+; CHECK: mul.f32
+  %x = fdiv float %a, %divisor
+  %y = fdiv float %b, %divisor
+  %z = select i1 %pred, float %x, float %y
+  ret float %z
+}
+
+; CHECK-LABEL: repeated_div_fast_ftz
+define float @repeated_div_fast_ftz(i1 %pred, float %a, float %b, float %divisor) #0 #1 {
+; CHECK: rcp.approx.ftz.f32
+; CHECK: mul.ftz.f32
+; CHECK: mul.ftz.f32
+  %x = fdiv float %a, %divisor
+  %y = fdiv float %b, %divisor
+  %z = select i1 %pred, float %x, float %y
+  ret float %z
+}
+
 attributes #0 = { "unsafe-fp-math" = "true" }
 attributes #1 = { "nvptx-f32ftz" = "true" }