Skip to content

Commit 9627500

Browse files
committed
Improve asserts and restructure code flow.
1 parent a2424d8 commit 9627500

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

llvm/lib/Target/AArch64/AArch64MIPeepholeOpt.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ INITIALIZE_PASS(AArch64MIPeepholeOpt, "aarch64-mi-peephole-opt",
164164
template <typename T>
165165
static bool splitBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc, T &Imm2Enc) {
166166
T UImm = static_cast<T>(Imm);
167+
assert(UImm && (UImm != ~static_cast<T>(0)) && "Invalid immediate!");
167168

168169
// The bitmask immediate consists of consecutive ones. Let's say there is
169170
// constant 0b00000000001000000000010000000000 which does not consist of
@@ -194,6 +195,8 @@ static bool splitBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc, T &Imm2Enc) {
194195
template <typename T>
195196
static bool splitDisjointBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc,
196197
T &Imm2Enc) {
198+
assert(Imm && (Imm != ~static_cast<T>(0)) && "Invalid immediate!");
199+
197200
// Try to split a bitmask of the form 0b00000000011000000000011110000000 into
198201
// two disjoint masks such as 0b00000000011000000000000000000000 and
199202
// 0b00000000000000000000011110000000 where the inclusive/exclusive OR of the
@@ -207,17 +210,14 @@ static bool splitDisjointBitmaskImm(T Imm, unsigned RegSize, T &Imm1Enc,
207210
(static_cast<T>(1) << LowestBitSet);
208211
// Create a disjoint mask for the remaining ones.
209212
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-
}
219213

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;
221221
}
222222

223223
template <typename T>

0 commit comments

Comments
 (0)