[LLVMdev] DAGCombiner: (S|U)REM
Chris Lattner
sabre at nondot.org
Tue Jun 19 09:21:31 PDT 2007
On Tue, 19 Jun 2007, Dietmar Ebner wrote:
>> Actually, perhaps not. The reason that dag combine does this is that it
>> knows tricky ways to turn division by a constant into multiplication by a
>> constant (plus magic). Doing this xform allows the rem case to take
>> advantage of this. That said, I'm sure there are some targets and some
>> cases where this is counter productive. Are you hitting one?
> yes. i'm compiling for a target without native div/rem instructions.
> when compiling expressions like (a % 3), the dagcombiner turns them into
> (a-(a/3)*3) which is not simplified later on. this is quite expensive
> since the multiply is not pipelined and the div requires a libcall while
> the same could have been achieved with a (S|U)REM_I32 libcall.
>
> the problem is that the involved "magic" int TargetLowering has certain
> requirements such as MULHU support, which is not available on my
> architecture. i guess the best way is to check this conditions beforehand
> in the DAGCombiner, right?
Ah, right. The problem is that you don't have div *or* MULHU/MULHS. I
think you're right: please conditionalize the xform on the availability of
these instructions. Having either MULH* or DIV should allow the xform.
-Chris
--
http://nondot.org/sabre/
http://llvm.org/
More information about the llvm-dev
mailing list