This is a fix http://reviews.llvm.org/D8219 applied also to AArch64FastISel, as it has a copy of the code fixed previously.
The code looks reasonable, but that test isn't going to work. It'll fail if those other backends aren't compiled in (lit.local.cfg explicitly requires only X86 in the test/CodeGen/X86 directory). Your best bet is probably to copy it into each target's subdirectory.
Thank you for doing this fix, chfast.
I think we can probably copy this test into the directory of each target. Since the target R600 is still falling, we can add the part for R600 separately in a different patch.
I think it's reasonable with just the AArch64 test added.
I'm not a massive fan of the way the test is written in general, but it might actually allow it to live in test/Generic once R600 is fixed.