I'm trying to fix bug 12802 . The problem is that the C statement "return ((long)&x) - 600000000;" (where x is a variable defined at file scope) generates the code "movl $x-600000000, %eax" while it should be "movq $x-600000000, %rax". This means that the result is incorrectly zero-extended instead of sign-extended, causing an error with some linkers and incorrect results with some other linkers. It seems like the wrong instruction is selected in X86DAGToDAGISel::SelectMOV64Imm32. I tried to add an extra check that makes the function return false if the offset of the GlobalAddressSDNode is negative, but this causes the instruction selector to not select an instruction at all (it fails with a "Cannot select" error). Any help is appreciated.