diff options
author | Shawn Landden <shawn@git.icu> | 2019-06-13 05:26:17 +0000 |
---|---|---|
committer | Shawn Landden <shawn@git.icu> | 2019-06-13 05:26:17 +0000 |
commit | 8b142bcc3f21f279303e28ea2e060acc79a3cbe4 (patch) | |
tree | 223dc3f95fcdbf4d4a93d42a4a563d26459114dc /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 2bf25681509add1d9987ca7dada2fffeb95da4c1 (diff) | |
download | bcm5719-llvm-8b142bcc3f21f279303e28ea2e060acc79a3cbe4.tar.gz bcm5719-llvm-8b142bcc3f21f279303e28ea2e060acc79a3cbe4.zip |
[SimplifyCFG] reverting preliminary Switch patches again
This reverts 363226 and 363227, both NFC intended
I swear I fixed the test case that is failing, and ran
the tests, but I will look into it again.
llvm-svn: 363229
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index ec574eaa81d..90b552035af 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -5559,23 +5559,25 @@ static bool ReduceSwitchRange(SwitchInst *SI, IRBuilder<> &Builder, // Now we have signed numbers that have been shifted so that, given enough // precision, there are no negative values. Since the rest of the transform // is bitwise only, we switch now to an unsigned representation. + uint64_t GCD = 0; + for (auto &V : Values) + GCD = GreatestCommonDivisor64(GCD, (uint64_t)V); - // This transform can be done speculatively because it is so cheap - it - // results in a single rotate operation being inserted. + // This transform can be done speculatively because it is so cheap - it results + // in a single rotate operation being inserted. This can only happen if the + // factor extracted is a power of 2. + // FIXME: If the GCD is an odd number we can multiply by the multiplicative + // inverse of GCD and then perform this transform. // FIXME: It's possible that optimizing a switch on powers of two might also // be beneficial - flag values are often powers of two and we could use a CLZ // as the key function. + if (GCD <= 1 || !isPowerOf2_64(GCD)) + // No common divisor found or too expensive to compute key function. + return false; - // countTrailingZeros(0) returns 64. As Values is guaranteed to have more than - // one element and LLVM disallows duplicate cases, Shift is guaranteed to be - // less than 64. - unsigned Shift = 64; + unsigned Shift = Log2_64(GCD); for (auto &V : Values) - Shift = std::min(Shift, countTrailingZeros((uint64_t)V)); - assert(Shift < 64); - if (Shift > 0) - for (auto &V : Values) - V = (int64_t)((uint64_t)V >> Shift); + V = (int64_t)((uint64_t)V >> Shift); if (!isSwitchDense(Values)) // Transform didn't create a dense switch. |