[llvm-commits] [llvm] r160058 - in /llvm/trunk: lib/Support/APInt.cpp test/CodeGen/X86/divide-by-constant.ll
Chandler Carruth
chandlerc at google.com
Wed Jul 11 11:39:02 PDT 2012
Maybe we should generate a test case (or unit test) with all of the
possible 8-bit ones?
On Wed, Jul 11, 2012 at 11:31 AM, Benjamin Kramer
<benny.kra at googlemail.com>wrote:
> Author: d0k
> Date: Wed Jul 11 13:31:59 2012
> New Revision: 160058
>
> URL: http://llvm.org/viewvc/llvm-project?rev=160058&view=rev
> Log:
> PR13326: Fix a subtle edge case in the udiv -> magic multiply generator.
>
> This caused 6 of 65k possible 8 bit udivs to be wrong.
>
> Modified:
> llvm/trunk/lib/Support/APInt.cpp
> llvm/trunk/test/CodeGen/X86/divide-by-constant.ll
>
> Modified: llvm/trunk/lib/Support/APInt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=160058&r1=160057&r2=160058&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/APInt.cpp (original)
> +++ llvm/trunk/lib/Support/APInt.cpp Wed Jul 11 13:31:59 2012
> @@ -1446,7 +1446,7 @@
> APInt signedMin = APInt::getSignedMinValue(d.getBitWidth());
> APInt signedMax = APInt::getSignedMaxValue(d.getBitWidth());
>
> - nc = allOnes - (-d).urem(d);
> + nc = allOnes - (allOnes - d).urem(d);
> p = d.getBitWidth() - 1; // initialize p
> q1 = signedMin.udiv(nc); // initialize q1 = 2p/nc
> r1 = signedMin - q1*nc; // initialize r1 = rem(2p,nc)
>
> Modified: llvm/trunk/test/CodeGen/X86/divide-by-constant.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/divide-by-constant.ll?rev=160058&r1=160057&r2=160058&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/divide-by-constant.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/divide-by-constant.ll Wed Jul 11 13:31:59
> 2012
> @@ -71,3 +71,24 @@
> ; CHECK-NOT: shrl
> ; CHECK: ret
> }
> +
> +; PR13326
> +define i8 @test8(i8 %x) nounwind {
> + %div = udiv i8 %x, 78
> + ret i8 %div
> +; CHECK: test8:
> +; CHECK: shrb %
> +; CHECK: imull $211
> +; CHECK: shrl $13
> +; CHECK: ret
> +}
> +
> +define i8 @test9(i8 %x) nounwind {
> + %div = udiv i8 %x, 116
> + ret i8 %div
> +; CHECK: test9:
> +; CHECK: shrb $2
> +; CHECK: imull $71
> +; CHECK: shrl $11
> +; CHECK: ret
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120711/774e14bf/attachment.html>
More information about the llvm-commits
mailing list