From 8d7285d0e5eb5937a6682e884b883516377e903d Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Mon, 21 Feb 2011 00:22:02 +0000 Subject: The signed version of our "magic number" computation for the integer approximation of a constant had a minor typo introduced when copying it from the book, which caused it to favor negative approximations over positive approximations in many cases. Positive approximations require fewer operations beyond the multiplication. In the case of division by 3, we still generate code that is a single instruction larger than GCC's code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126097 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/APInt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Support/APInt.cpp') diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 77033428b5..08f36d2af3 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -1505,7 +1505,7 @@ APInt::ms APInt::magic() const { r2 = r2 - ad; } delta = ad - r2; - } while (q1.ule(delta) || (q1 == delta && r1 == 0)); + } while (q1.ult(delta) || (q1 == delta && r1 == 0)); mag.m = q2 + 1; if (d.isNegative()) mag.m = -mag.m; // resulting magic number -- cgit v1.2.3