[PATCH] D28582: [SCEV] Simplify SolveLinEquationWithOverflow a bit.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 15:06:57 PST 2017
efriedma created this revision.
efriedma added a reviewer: sanjoy.
efriedma added a subscriber: llvm-commits.
efriedma set the repository for this revision to rL LLVM.
Herald added a subscriber: mzolotukhin.
Cleanup in preparation for generalizing it.
Repository:
rL LLVM
https://reviews.llvm.org/D28582
Files:
lib/Analysis/ScalarEvolution.cpp
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -7037,15 +7037,16 @@
APInt AD = A.lshr(Mult2).zext(BW + 1); // AD = A / D
APInt Mod(BW + 1, 0);
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);
// 4. Compute the minimum unsigned root of the equation:
// I * (B / D) mod (N / D)
- APInt Result = (I * B.lshr(Mult2).zext(BW + 1)).urem(Mod);
+ // To simplify the computation, we factor out the divide by D:
+ // (I * B mod N) / D
+ APInt Result = (I * B).lshr(Mult2);
- // The result is guaranteed to be less than 2^BW so we may truncate it to BW
- // bits.
- return SE.getConstant(Result.trunc(BW));
+ return SE.getConstant(Result);
}
/// Find the roots of the quadratic equation for the given quadratic chrec
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28582.84032.patch
Type: text/x-patch
Size: 1024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170111/86f41c76/attachment.bin>
More information about the llvm-commits
mailing list