[llvm-commits] [llvm] r132537 - /llvm/trunk/utils/TableGen/Record.cpp
Nick Lewycky
nicholas at mxc.ca
Fri Jun 3 01:25:39 PDT 2011
Author: nicholas
Date: Fri Jun 3 03:25:39 2011
New Revision: 132537
URL: http://llvm.org/viewvc/llvm-project?rev=132537&view=rev
Log:
Rework the logic to not rely on undefined behaviour (1LL << 64). Also simplify.
Modified:
llvm/trunk/utils/TableGen/Record.cpp
Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=132537&r1=132536&r2=132537&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Fri Jun 3 03:25:39 2011
@@ -68,14 +68,9 @@
/// canFitInBitfield - Return true if the number of bits is large enough to hold
/// the integer value.
static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
- if (Value >= 0) {
- if (Value & ~((1LL << NumBits) - 1))
- return false;
- } else if ((Value >> NumBits) != -1 || (Value & (1LL << (NumBits-1))) == 0) {
- return false;
- }
-
- return true;
+ // For example, with NumBits == 4, we permit Values from [-7 .. 15].
+ return (NumBits >= sizeof(Value) * 8) ||
+ (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
}
/// convertValue from Int initializer to bits type: Split the integer up into the
More information about the llvm-commits
mailing list