[LLVMdev] Integer divide by zero

dag at cray.com dag at cray.com
Tue Apr 16 10:01:59 PDT 2013


Chandler Carruth <chandlerc at google.com> writes:

> Yes, and this is the point I was driving at with the comments about a
> target specific optimization. It is reasonable for the x86 backend to
> recognize the pattern of testing for a zero divisor and trapping if it
> occurs, and transform that into an unconditional divide relying on the
> hardware trap instead. I think it is not unreasonable to have this
> strategy result in one of two generated code patterns in the
> overwhelming majority of cases:
>
> 1) An unconditional trap because the optimizer proved divide by zero
> 2) A direct divide instruction which relies on the x86 trapping
> behavior.
>
> That said, it remains a fairly significant amount of work to arrive at
> this place. Just trying to point out a reasonable approach to arriving
> there.

I agree that this is potentially a good approach.  I also agree that it
is a significant amount of work.

Given infinite resources, I think your solution makes the most sense.
Given limited resources, I'm not sure.  But Cameron has said he won't
push anything upstream that people aren't comfortable with.

                                  -David



More information about the llvm-dev mailing list