[PATCH] D24816: [Target] move reciprocal estimate settings from TargetOptions to TargetLowering

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 14:08:45 PDT 2016


spatel added a comment.

In https://reviews.llvm.org/D24816#549962, @mehdi_amini wrote:

> I'm not sure how the mrecip works: is it adding refinement only to prevent some specific "fast-math" (i.e. unsafe) transformations?


'Prevent' is not the right description. It can be used to inhibit or enhance the effects of fast-math, but it should have no effect without fast-math.

> I.e. if the fast-math flag is dropped, what is the impact of the "mrecip" attribute?


If fast-math is off, mrecip should have no impact. We should be able to confirm this independently of this patch.

Here's an IR playpen we can use to walk through some scenarios:

  target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-apple-macosx10.11.0"
  
  define float @foo(float %x) #0 {
    %y = call fast float @bar(float %x)
    ret float %y
  }
  
  define float @bar(float %x) #1 {
    %y = call float @baz(float %x)
    ret float %y
  }
  
  define float @baz(float %x) #2 {
    %y = fdiv float 1.0, %x
    ret float %y
  }
  
  attributes #0 = { "unsafe-fp-math"="false" "mrecip"="divf:0" }
  attributes #1 = { "unsafe-fp-math"="true" "mrecip"="divf:1" }
  attributes #2 = { "unsafe-fp-math"="true" "mrecip"="divf:0" }

Notice that the backend still largely ignores the instruction-level FMF, so you can delete any 'fast' on the calls or fdiv, and there should be no difference in codegen.

I tried some experiments using something like this:
$ ./opt -inline fdiv.ll -S  | ./llc -o -

I haven't seen anything go wrong yet, but I'm still trying. :)

> Bonus points: where is it documented?


That's an easy one - we have no docs. The intent was to mimic and expand on the gcc flag with the same name:
https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/x86-Options.html#x86-Options
https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/RS_002f6000-and-PowerPC-Options.html#RS_002f6000-and-PowerPC-Options


https://reviews.llvm.org/D24816





More information about the llvm-commits mailing list