Factor out the code for sign-extending/truncating gep indices