@@ -21,59 +21,6 @@ namespace opt {
21
21
namespace {
22
22
constexpr uint32_t kExtractCompositeIdInIdx = 0 ;
23
23
24
- // Returns the value obtained by extracting the |number_of_bits| least
25
- // significant bits from |value|, and sign-extending it to 64-bits.
26
- uint64_t SignExtendValue (uint64_t value, uint32_t number_of_bits) {
27
- if (number_of_bits == 64 ) return value;
28
-
29
- uint64_t mask_for_sign_bit = 1ull << (number_of_bits - 1 );
30
- uint64_t mask_for_significant_bits = (mask_for_sign_bit << 1 ) - 1ull ;
31
- if (value & mask_for_sign_bit) {
32
- // Set upper bits to 1
33
- value |= ~mask_for_significant_bits;
34
- } else {
35
- // Clear the upper bits
36
- value &= mask_for_significant_bits;
37
- }
38
- return value;
39
- }
40
-
41
- // Returns the value obtained by extracting the |number_of_bits| least
42
- // significant bits from |value|, and zero-extending it to 64-bits.
43
- uint64_t ZeroExtendValue (uint64_t value, uint32_t number_of_bits) {
44
- if (number_of_bits == 64 ) return value;
45
-
46
- uint64_t mask_for_first_bit_to_clear = 1ull << (number_of_bits);
47
- uint64_t mask_for_bits_to_keep = mask_for_first_bit_to_clear - 1 ;
48
- value &= mask_for_bits_to_keep;
49
- return value;
50
- }
51
-
52
- // Returns a constant whose value is `value` and type is `type`. This constant
53
- // will be generated by `const_mgr`. The type must be a scalar integer type.
54
- const analysis::Constant* GenerateIntegerConstant (
55
- const analysis::Integer* integer_type, uint64_t result,
56
- analysis::ConstantManager* const_mgr) {
57
- assert (integer_type != nullptr );
58
-
59
- std::vector<uint32_t > words;
60
- if (integer_type->width () == 64 ) {
61
- // In the 64-bit case, two words are needed to represent the value.
62
- words = {static_cast <uint32_t >(result),
63
- static_cast <uint32_t >(result >> 32 )};
64
- } else {
65
- // In all other cases, only a single word is needed.
66
- assert (integer_type->width () <= 32 );
67
- if (integer_type->IsSigned ()) {
68
- result = SignExtendValue (result, integer_type->width ());
69
- } else {
70
- result = ZeroExtendValue (result, integer_type->width ());
71
- }
72
- words = {static_cast <uint32_t >(result)};
73
- }
74
- return const_mgr->GetConstant (integer_type, words);
75
- }
76
-
77
24
// Returns a constants with the value NaN of the given type. Only works for
78
25
// 32-bit and 64-bit float point types. Returns |nullptr| if an error occurs.
79
26
const analysis::Constant* GetNan (const analysis::Type* type,
@@ -1730,7 +1677,7 @@ BinaryScalarFoldingRule FoldBinaryIntegerOperation(uint64_t (*op)(uint64_t,
1730
1677
uint64_t result = op (ia, ib);
1731
1678
1732
1679
const analysis::Constant* result_constant =
1733
- GenerateIntegerConstant (integer_type, result, const_mgr );
1680
+ const_mgr-> GenerateIntegerConstant (integer_type, result);
1734
1681
return result_constant;
1735
1682
};
1736
1683
}
@@ -1745,7 +1692,7 @@ const analysis::Constant* FoldScalarSConvert(
1745
1692
const analysis::Integer* integer_type = result_type->AsInteger ();
1746
1693
assert (integer_type && " The result type of an SConvert" );
1747
1694
int64_t value = a->GetSignExtendedValue ();
1748
- return GenerateIntegerConstant (integer_type, value, const_mgr );
1695
+ return const_mgr-> GenerateIntegerConstant (integer_type, value);
1749
1696
}
1750
1697
1751
1698
// A scalar folding rule that folds OpUConvert.
@@ -1762,8 +1709,8 @@ const analysis::Constant* FoldScalarUConvert(
1762
1709
// If the operand was an unsigned value with less than 32-bit, it would have
1763
1710
// been sign extended earlier, and we need to clear those bits.
1764
1711
auto * operand_type = a->type ()->AsInteger ();
1765
- value = ZeroExtendValue (value, operand_type->width ());
1766
- return GenerateIntegerConstant (integer_type, value, const_mgr );
1712
+ value = utils::ClearHighBits (value, 64 - operand_type->width ());
1713
+ return const_mgr-> GenerateIntegerConstant (integer_type, value);
1767
1714
}
1768
1715
} // namespace
1769
1716
0 commit comments