[LLVMdev] Convert fdiv - X/Y -> X*1/Y

Weiming Zhao weimingz at codeaurora.org
Thu Aug 8 09:57:26 PDT 2013


Hi Chad,

 

Instcombine can create new instructions (e.g. some code in combine-select
does that). 

We can do it in DAG as well. (it may be easier to implement in DAG. It will
create multiple 1/Y, but later pass should remove the redundancy)

Btw,  it seems the transformation is beneficial only when %d is used as a
common denominator by >2 nominators. 

 

Thanks,

Weiming

From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
Behalf Of Chad Rosier
Sent: Thursday, August 08, 2013 9:25 AM
To: llvmdev
Subject: [LLVMdev] Convert fdiv - X/Y -> X*1/Y

 

I would like to transform X/Y -> X*1/Y.  Specifically, I would like to
convert:

define void @t1a(double %a, double %b, double %d) {
entry:
  %div = fdiv fast double %a, %d
  %div1 = fdiv fast double %b, %d
  %call = tail call i32 @foo(double %div, double %div1)
  ret void
}

to:

define void @t1b(double %a, double %b, double %d) {
entry:
  %div = fdiv fast double 1.000000e+00, %d
  %mul = fmul fast double %div, %a
  %mul1 = fmul fast double %div, %b
  %call = tail call i32 @foo(double %mul, double %mul1)
  ret void
}

Is such a transformation best done as a (target-specific) DAG combine?

A similar instcombine already exists for the X/C->X*1/C case (see the
CvtFDivConstToReciprocal function in InstCombineMlDivRem.cpp), but I don't
believe the above can be done as an instcombine as it creates a new
instruction (in addition to replacing the original).  Also, I only want to
perform the transformation if there are multiple uses of 1/Y (like in my
test case).  Otherwise, the transformation replaces a fdiv with a fdiv+fmul
pair, which I doubt would be profitable.

FWIW, I'm also pretty sure this combine requires -fast-math.

Can someone point me in the right direction?

 Thanks,
  Chad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130808/1e0acc88/attachment.html>


More information about the llvm-dev mailing list