<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div style="font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);"><span style="text-transform: none;">Hi All</span></div>
<div style="font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">I  am working on JDK-8216554 — optimizing constant loading on PPC64 by replacing the two-instruction sequence (ADDIS + LD) with a single LD instruction when the method TOC offset fits in
 a 16-bit signed displacement.</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; margin: 0px 10px; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<b>Background:</b></div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
Currently on PPC64, all long constant loads in C2-compiled code go through a two-node hi/lo pair (loadConL_hi + loadConL_lo), emitting ADDIS + LD regardless of the constant pool offset. This is because the decision was hardcoded as:</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
  const bool large_constant_pool = true; // TODO: PPC port C->cfg()->_consts_size > 4000;</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
The TODO was never implemented.</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
 The intent was to check the constant pool size at postalloc time and choose between a single-node (small) or two-node (large) path. However, the constant pool size is not available at postalloc — constant_table().size() returns 0 on PPC64 because the platform
 uses its own TOC-based constant pool via MacroAssembler::long_constant(), bypassing the generic C2 ConstantTable.</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
Approach:</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks to Dean Long's suggestion of creating a single smart node that decides its instruction encoding at emit time, I create a single loadConLNode at postalloc and defer the instruction selection to the emit stage. During emit, the method TOC offset (toc_offset)
 for each constant is known and stable, so the decision is made per-constant:</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
  int toc_offset = __ offset_to_method_toc(const_toc_addr);</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
  if (Assembler::is_simm(toc_offset, 16)) {</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      // Small path: single LD + NOP (8 bytes)</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      __ ld(dst, toc_offset, toc_reg);</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      __ nop();</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
  } else {</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      // Large path: ADDIS + LD (8 bytes)</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      __ addis(dst, toc_reg, largeoffset_si16_si16_hi(toc_offset));</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
      __ ld(dst, largeoffset_si16_si16_lo(toc_offset), dst);</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
  }</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
Both paths emit exactly 8 bytes, matching the scratch emit reservation. The NOP in the small path maintains size consistency.</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
One thing I would like confirmation on: is it correct to rely on the method TOC offset (toc_offset) at emit time for the instruction selection? </div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
I want to confirm there are no edge cases where this assumption breaks.</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
I would appreciate any feedback on this approach.</div>
<div style="direction: ltr; text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="text-align: left; text-indent: 0px; text-transform: none; font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks,</div>
<div style="font-family: Aptos; font-size: 12pt; color: rgb(0, 0, 0);"><span style="text-transform: none;">Suchismith Roy</span></div>
<div style="direction: ltr; font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="direction: ltr; font-family: Aptos, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>