@@ -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