[llvm] r285312 - ARM: ensure that the Windows DBZ check is in range

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 13:54:13 PDT 2016


On Thu, 27 Oct 2016, Saleem Abdulrasool via llvm-commits wrote:

> Author: compnerd
> Date: Thu Oct 27 11:59:22 2016
> New Revision: 285312
>
> URL: http://llvm.org/viewvc/llvm-project?rev=285312&view=rev
> Log:
> ARM: ensure that the Windows DBZ check is in range
>
> The Windows ARM target expects the compiler to emit a division-by-zero check.
> The check would use the form of:
>
>    cmp r?, #0
>    cbz .Ltrap
>    b .Lbody
>  .Lbody:
>    ...
>  .Ltrap:
>    udf #249 @ __brkdiv0
>
> This works great most of the time.  However, if the body of the function is
> greater than 127 bytes, the branch target limitation of cbz becomes an issue.
> This occurs in the unoptimized code generation cases sometimes (like in
> compiler-rt).
>
> Since this is a matter of correctness, possibly pay a small penalty instead.  We
> now form this slightly differently:
>
>    cbnz .Lbody
>    udf #249 @ __brkdiv0
>  .Lbody:
>    ...
>
> The positive case is through the branch instead of being the next instruction.
> However, because of the basic block layout, the negated branch is going to be
> a short distance always (2 bytes away, after the inserted __brkdiv0).
>
> The new t__brkdiv0 instruction is required to explicitly mark the instruction as
> a terminator as the generic UDF instruction is not a terminator.
>
> Addresses PR30532!

I've run into the same issue, reported in a different PR also, PR30356. 
But despite this fix, the issue still triggers (although less often than 
before I guess).

I posted a reduced example where it triggers, in that bug report. If 
necessary, I can also test with a larger code base (where I found this 
issue).

// Martin


More information about the llvm-commits mailing list