[llvm-dev] [RFC] Improving integer divide optimization (related to D12082)

Steve King via llvm-dev llvm-dev at lists.llvm.org
Wed Aug 19 13:45:08 PDT 2015

Hello LLVM,  A recent commit creates the isIntDivCheap() target query.


The current approach has a couple shortcomings.

First, when targets decide divide is cheap, the DAGCombiner ignores
obvious power-of-2 optimizations.  In the targets I know, shifts are
cheaper than divides in both speed and size.  The target cannot see
the value in the isIntDivCheap() call, so cannot itself check for
power-of-2 cases.

Second, isIntDivCheap passes a MinSize flag to the target, which is
true for -Oz (MinSize function attribute).  However, the MinSize flags
is false for -Os (OptimizeSize function attribute).  Both of these try
to optimize for size and targets may like to indicate cheap division
in both cases, or perhaps for other function attributes in the future.

I think some improvements would be helpful:
The DAGCombiner should always optimize for power-of-2 division before
considering the general integer case.
isIntDivCheap() should pass the MachineFunction to the target rather
than just a MinSize flag.  If it cares, the target can check function
attributes as it sees fit.

Does this sound sensible?


More information about the llvm-dev mailing list