@@ -99,6 +99,13 @@ static unsigned log2LdstWidth(unsigned Opcode) {
99
99
switch (Opcode) {
100
100
default :
101
101
llvm_unreachable (" Unexpected opcode" );
102
+ case RISCV::LBU:
103
+ case RISCV::SB:
104
+ return 0 ;
105
+ case RISCV::LH:
106
+ case RISCV::LHU:
107
+ case RISCV::SH:
108
+ return 1 ;
102
109
case RISCV::LW:
103
110
case RISCV::SW:
104
111
case RISCV::FLW:
@@ -112,17 +119,47 @@ static unsigned log2LdstWidth(unsigned Opcode) {
112
119
}
113
120
}
114
121
122
+ // Return bit field size of immediate operand of Opcode.
123
+ static unsigned offsetMask (unsigned Opcode) {
124
+ switch (Opcode) {
125
+ default :
126
+ llvm_unreachable (" Unexpected opcode" );
127
+ case RISCV::LBU:
128
+ case RISCV::SB:
129
+ return maskTrailingOnes<unsigned >(2U );
130
+ case RISCV::LH:
131
+ case RISCV::LHU:
132
+ case RISCV::SH:
133
+ return maskTrailingOnes<unsigned >(1U );
134
+ case RISCV::LW:
135
+ case RISCV::SW:
136
+ case RISCV::FLW:
137
+ case RISCV::FSW:
138
+ case RISCV::LD:
139
+ case RISCV::SD:
140
+ case RISCV::FLD:
141
+ case RISCV::FSD:
142
+ return maskTrailingOnes<unsigned >(5U );
143
+ }
144
+ }
145
+
115
146
// Return a mask for the offset bits of a non-stack-pointer based compressed
116
147
// load/store.
117
148
static uint8_t compressedLDSTOffsetMask (unsigned Opcode) {
118
- return 0x1f << log2LdstWidth (Opcode);
149
+ return offsetMask (Opcode) << log2LdstWidth (Opcode);
119
150
}
120
151
121
152
// Return true if Offset fits within a compressed stack-pointer based
122
153
// load/store.
123
154
static bool compressibleSPOffset (int64_t Offset, unsigned Opcode) {
124
- return log2LdstWidth (Opcode) == 2 ? isShiftedUInt<6 , 2 >(Offset)
125
- : isShiftedUInt<6 , 3 >(Offset);
155
+ // Compressed sp-based loads and stores only work for 32/64 bits.
156
+ switch (log2LdstWidth (Opcode)) {
157
+ case 2 :
158
+ return isShiftedUInt<6 , 2 >(Offset);
159
+ case 3 :
160
+ return isShiftedUInt<6 , 3 >(Offset);
161
+ }
162
+ return false ;
126
163
}
127
164
128
165
// Given an offset for a load/store, return the adjustment required to the base
@@ -147,6 +184,10 @@ static bool isCompressibleLoad(const MachineInstr &MI) {
147
184
switch (MI.getOpcode ()) {
148
185
default :
149
186
return false ;
187
+ case RISCV::LBU:
188
+ case RISCV::LH:
189
+ case RISCV::LHU:
190
+ return STI.hasStdExtZcb ();
150
191
case RISCV::LW:
151
192
case RISCV::LD:
152
193
return STI.hasStdExtCOrZca ();
@@ -164,6 +205,9 @@ static bool isCompressibleStore(const MachineInstr &MI) {
164
205
switch (MI.getOpcode ()) {
165
206
default :
166
207
return false ;
208
+ case RISCV::SB:
209
+ case RISCV::SH:
210
+ return STI.hasStdExtZcb ();
167
211
case RISCV::SW:
168
212
case RISCV::SD:
169
213
return STI.hasStdExtCOrZca ();
0 commit comments