Skip to content

Commit 29be80d

Browse files
authored
Merge pull request #75 from OpenVADL/bugfix/built-in-opt
iss: Fix SRLIW RISC-V instruction
2 parents 783bd51 + d9d6c24 commit 29be80d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

vadl/main/vadl/iss/passes/IssBuiltInSimplificationPass.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ private void transformRightShiftToExtract(BuiltInCall call, TcgExtend extend) {
129129
var offset = safeShift;
130130
var length = sub(valueLength, safeShift);
131131

132+
if (call.usageCount() == 1) {
133+
var user = call.usages().findFirst().get();
134+
if (user instanceof IssConstExtractNode extNode
135+
&& extNode.preservedWidth() >= valueWidth) {
136+
// if the only user is an extract node that has the same
137+
// preserve with as the extracted value, we can just
138+
// use its sign extend mode and delete it
139+
if (extNode.preservedWidth() > valueWidth
140+
|| extNode.isSigned() == (extend == TcgExtend.SIGN)
141+
) {
142+
extNode.replaceByNothingAndDelete();
143+
}
144+
}
145+
}
146+
132147
// Create the extraction node and replace the original call.
133148
var extract = new IssValExtractNode(extend, valueArg, offset, length, call.type());
134149
call.replaceAndDelete(extract);
@@ -138,14 +153,5 @@ private void transformRightShiftToExtract(BuiltInCall call, TcgExtend extend) {
138153
&& constExtract.preservedWidth() >= valueWidth) {
139154
constExtract.replaceByNothingAndDelete();
140155
}
141-
extract.usages().filter(IssConstExtractNode.class::isInstance)
142-
.map(IssConstExtractNode.class::cast)
143-
.toList() // prevent concurrent modification
144-
.forEach(user -> {
145-
if (user.isSigned() && user.preservedWidth() >= valueWidth
146-
&& user.toWidth() == targetSize) {
147-
user.replaceByNothingAndDelete();
148-
}
149-
});
150156
}
151157
}

0 commit comments

Comments
 (0)