'Fix negative indices by adding the size to them.  Positive
indices are left untouched.'

def fix_index(self, idx):

    is_negative = self._builder.icmp_signed('<', idx, ir.Constant(idx.type, 0))
    wrapped_index = self._builder.add(idx, self.size)
    return self._builder.select(is_negative, wrapped_index, idx)
