stg_IND[_STATIC] should inspect the indirectees pointer tag before jumping into the indirectees entry code.
Currently this is implemented as:
INFO_TABLE(stg_IND,1,0,IND,"IND","IND")
{
TICK_ENT_DYN_IND(); /* tick */
R1 = UNTAG(StgInd_indirectee(R1));
TICK_ENT_VIA_NODE();
jump %GET_ENTRY(R1) [R1];
}
I think we should try if this implementation:
{
W_ tag;
TICK_ENT_DYN_IND(); /* tick */
R1 = (StgInd_indirectee(R1));
tag = GETTAG(R1);
if(tag == 0) {
// R1 = UNTAG(R1);
TICK_ENT_VIA_NODE();
jump %GET_ENTRY(R1) [R1];
} else {
jump W_[Sp](R1);
}
}
Why so? It's my understanding we sometimes we end up in situations where we have:
x -----> THUNK
y --/
We evaluate x, which leaves us with this relevant part:
y --> IND -[tagged]-> CON
Now if we evaluate y
it will jump into the entry code for CON
which is just a waste of time. It should rather just jump to the continuation.
I had tried this implementation locally and it seemed to work fine and reduce overall instructions executed. But I (or someone else!) needs to properly benchmark this before we make this change.