[PATCH] D61151: [SimpligyCFG] NFC, remove GCD that was only used for powers of two
Shawn Landden via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 28 01:23:17 PDT 2019
shawnl updated this revision to Diff 197005.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61151/new/
https://reviews.llvm.org/D61151
Files:
lib/Transforms/Utils/SimplifyCFG.cpp
Index: lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyCFG.cpp
+++ lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5543,25 +5543,24 @@
// 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 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.
+ // in a single rotate operation being inserted.
// 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;
- unsigned Shift = Log2_64(GCD);
+ // Cttz often has an edge condition on 0 which means that the bit-width
+ // is important, however here there is no such edge condition because if
+ // 0 is the only value then a shift does nothing, and LLVM requires
+ // well-formed IR to not have duplicate cases (so the minimum will not
+ // be BitWidth)
+ unsigned Shift = 64;
for (auto &V : Values)
- V = (int64_t)((uint64_t)V >> Shift);
+ Shift = std::min(Shift, countTrailingZeros((uint64_t)V);
+ if (Shift > 0)
+ for (auto &V : Values)
+ V = (int64_t)((uint64_t)V >> Shift);
if (!isSwitchDense(Values))
// Transform didn't create a dense switch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61151.197005.patch
Type: text/x-patch
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190428/3d6cc0f2/attachment-0001.bin>
More information about the llvm-commits
mailing list