@@ -469,19 +469,26 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
469469 // If VarOffsets already holds a different pointer, abort.
470470 //
471471 // Example:
472- // Suppose LocalVarsOffsets = { (%ptr → 4) } from this GEP, and
473- // VarOffsets already has { (%ptr → 8) } from an inner GEP.
474- // After this loop, VarOffsets should become { (%ptr → 12) }.
472+ // 1) First GEP picks the idx’th element (each element is 8 bytes):
473+ // addr0 = base + idx * 8
474+ //
475+ // 2) Second GEP adds a fixed 4‐byte shift:
476+ // addr1 = addr0 + 4
477+ //
478+ // To turn that into a 4‐byte “lane” index we divide by 4:
479+ // lane = (idx * 8 + 4) / 4
480+ // = idx * (8 / 4) + (4 / 4)
481+ // = idx * 2 + 1
475482 for (auto &VarEntry : LocalVarsOffsets) {
476483 // If VarOffsets already records a different pointer, abort.
477484 if (!VarOffsets.empty () && !VarOffsets.count (VarEntry.first ))
478485 return nullptr ;
479486
480- // Look up whether we’ve seen this pointer before.
481- auto *Existing = VarOffsets. find (VarEntry. first );
482- if ( Existing == VarOffsets. end ())
483- VarOffsets.insert ({ VarEntry.first , VarEntry.second } );
484- else
487+ // Try to insert VarEntry.first with its offset; if that pointer is
488+ // already in VarOffsets, add the new offset to the existing one.
489+ auto [ Existing, Inserted] =
490+ VarOffsets.try_emplace ( VarEntry.first , VarEntry.second );
491+ if (!Inserted)
485492 Existing->second += VarEntry.second ;
486493 }
487494
0 commit comments