[9] RFR (S): 8152179: C2: Folding of unsigned loads is broken w/ @Stable

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Wed Mar 23 16:56:04 UTC 2016


Byte and short loads with small masks are converted to unsigned loads.
Constant folding logic for array elements doesn't respect unsigned loads 
and replace them with signed values.

It usually happens when a small mask is applied to the value produced by 
a signed load (see AndINode::Ideal [1]):

   byteArr [i] & 0x000F;  // AndI (LoadB 0x000F) => AndI (LoadUB 0xF)
   shortArr[i] & 0x000F;  // AndI (LoadS 0x000F) => AndI (LoadUS 0xF)

   byteArr [i] & 0x00FF;  // AndI (LoadB 0x00FF) => LoadUB
   shortArr[i] & 0xFFFF;  // AndI (LoadS 0xFFFF) => LoadUS

Field loads aren't affected since they are constant folded during parsing.

Testing: regression tests, hotspot/compiler/stable, JPRT


Best regards,
Vladimir Ivanov

PS: while experimenting with the fix, I found that constant folding of 
@Stable loads doesn't always happen. Filed 8152590 [2].


[2] https://bugs.openjdk.java.net/browse/JDK-8152590

More information about the hotspot-compiler-dev mailing list