On the example below (it is a hot code) value is converted to int, then back to long, and then compared to -1L - in this sequence casting to long is excessive.
https://github.com/apache/lucene-solr/blob/master/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java#L192
int term = (int) segValues.nextOrd();
while (term != -1L) {
; - org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts::countOneSegment@192 (line 204)
0x0000ffff801cbb80: ldr x10, [x15, #16] ; loading value
0x0000ffff801cbb84: mov w11, w10 ; l2i
0x0000ffff801cbb88: sxtw x10, w11 ; i2l
..
0x0000ffff801cbb90: cmn x10, #0x1 ; ifeq -1
https://github.com/apache/lucene-solr/blob/master/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetCounts.java#L192
int term = (int) segValues.nextOrd();
while (term != -1L) {
; - org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts::countOneSegment@192 (line 204)
0x0000ffff801cbb80: ldr x10, [x15, #16] ; loading value
0x0000ffff801cbb84: mov w11, w10 ; l2i
0x0000ffff801cbb88: sxtw x10, w11 ; i2l
..
0x0000ffff801cbb90: cmn x10, #0x1 ; ifeq -1