@@ -164,6 +164,7 @@ INITIALIZE_PASS(AArch64MIPeepholeOpt, "aarch64-mi-peephole-opt",
164
164
template <typename T>
165
165
static bool splitBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc, T &Imm2Enc) {
166
166
T UImm = static_cast <T>(Imm);
167
+ assert (UImm && (UImm != ~static_cast <T>(0 )) && " Invalid immediate!" );
167
168
168
169
// The bitmask immediate consists of consecutive ones. Let's say there is
169
170
// constant 0b00000000001000000000010000000000 which does not consist of
@@ -194,6 +195,8 @@ static bool splitBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc, T &Imm2Enc) {
194
195
template <typename T>
195
196
static bool splitDisjointBitmaskImm (T Imm, unsigned RegSize, T &Imm1Enc,
196
197
T &Imm2Enc) {
198
+ assert (Imm && (Imm != ~static_cast <T>(0 )) && " Invalid immediate!" );
199
+
197
200
// Try to split a bitmask of the form 0b00000000011000000000011110000000 into
198
201
// two disjoint masks such as 0b00000000011000000000000000000000 and
199
202
// 0b00000000000000000000011110000000 where the inclusive/exclusive OR of the
@@ -207,17 +210,14 @@ static bool splitDisjointBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc,
207
210
(static_cast <T>(1 ) << LowestBitSet);
208
211
// Create a disjoint mask for the remaining ones.
209
212
T NewImm2 = Imm & ~NewImm1;
210
- assert (((NewImm1 & NewImm2) == 0 ) && " Non-disjoint immediates!" );
211
-
212
- if (AArch64_AM::isLogicalImmediate (NewImm2, RegSize)) {
213
- assert (((NewImm1 | NewImm2) == Imm) && " Invalid immediates!" );
214
- assert (((NewImm1 ^ NewImm2) == Imm) && " Invalid immediates!" );
215
- Imm1Enc = AArch64_AM::encodeLogicalImmediate (NewImm1, RegSize);
216
- Imm2Enc = AArch64_AM::encodeLogicalImmediate (NewImm2, RegSize);
217
- return true ;
218
- }
219
213
220
- return false ;
214
+ // Do not split if NewImm2 is not a valid bitmask immediate.
215
+ if (!AArch64_AM::isLogicalImmediate (NewImm2, RegSize))
216
+ return false ;
217
+
218
+ Imm1Enc = AArch64_AM::encodeLogicalImmediate (NewImm1, RegSize);
219
+ Imm2Enc = AArch64_AM::encodeLogicalImmediate (NewImm2, RegSize);
220
+ return true ;
221
221
}
222
222
223
223
template <typename T>
0 commit comments