[PATCH] D28582: [SCEV] Simplify SolveLinEquationWithOverflow a bit.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 16:55:02 PST 2017
efriedma added inline comments.
================
Comment at: lib/Analysis/ScalarEvolution.cpp:7035
//
// (N / D) may need BW+1 bits in its representation. Hence, we'll use this
// bit width during computations.
----------------
sanjoy wrote:
> I don't understand why "(N / D) may need BW+1 bits in its representation" is true, btw. It seems to me `N/D` should always fit in `BW` bits.
Suppose D is 1. Then N/D == N == 2^BW; the largest possible value for a BW-bit integer is 2^BW-1.
================
Comment at: lib/Analysis/ScalarEvolution.cpp:7040
Mod.setBit(BW - Mult2); // Mod = N / D
- APInt I = AD.multiplicativeInverse(Mod);
+ // I is guaranteed to fit into BW bits, so truncate it.
+ APInt I = AD.multiplicativeInverse(Mod).trunc(BW);
----------------
sanjoy wrote:
> Add an assert here?
Sure.
Repository:
rL LLVM
https://reviews.llvm.org/D28582
More information about the llvm-commits
mailing list