[llvm] [X86][GlobalISel] Enable G_BRJT (PR #81811)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 13:04:43 PST 2024


e-kud wrote:

@RemiSEGARD The selected instruction doesn't work in pie mode as we use absolute address of `.rodata`. With `-no-pie` it works fine. So, we need to consider `TLI.isJumpTableRelative` during selection.
```
$ cat test.c
int square(int num, int x) {
        switch (num) {
                case 1:
                        return x * x;
                case 2:
                        return x + x;
                case 3:
                        return 0;
                case 4:
                        return 1;
        }
        return -1;
}
int main(int argc, char **argv) {
    return square(argc, argc);
}
$ clang -mllvm -global-isel=1 test.c -pie
/usr/bin/ld: /tmp/test-5b004b.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

I see that SelectionDAG expands `br_jt` into address calculation and `brind`. We can do the same by transforming `G_BRJT` into `G_BRINDIRECT`. Then we can add `GINodeEquiv<G_BRINDIRECT, brind>` and we should be able to match existing patterns from SelectionDAG avoiding manual selection. What do you think?

https://github.com/llvm/llvm-project/pull/81811


More information about the llvm-commits mailing list