Hi! The i386 backend has a splitter: (define_split [(match_operand 0 "tls_address_pattern")] "TARGET_TLS_DIRECT_SEG_REFS" [(match_dup 0)] "operands[0] = ix86_rewrite_tls_address (operands[0]);") which just copies the pattern of an insn and adjusts tls references in there. Unfortunately it doesn't really work with asm goto, which needs to be a JUMP_INSN rather than normal INSN. try_split uses the classify_insn function to determine the kind of insn it should create and that didn't have any code to handle asm goto.
The following patch adds that and also copies over the REG_LABEL_TARGET nodes from the original JUMP_INSN to the replacement JUMP_INSN. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-04-24 Jakub Jelinek <ja...@redhat.com> PR target/90193 * rtl.c (classify_insn): Return JUMP_INSN for asm goto. * emit-rtl.c (try_split): Copy over REG_LABEL_TARGET. * gcc.target/i386/pr90193.c: New test. --- gcc/rtl.c.jj 2019-01-01 12:37:17.429970488 +0100 +++ gcc/rtl.c 2019-04-22 16:06:08.537256974 +0200 @@ -746,6 +746,8 @@ classify_insn (rtx x) return CALL_INSN; if (ANY_RETURN_P (x)) return JUMP_INSN; + if (GET_CODE (x) == ASM_OPERANDS && ASM_OPERANDS_LABEL_VEC (x)) + return JUMP_INSN; if (GET_CODE (x) == SET) { if (GET_CODE (SET_DEST (x)) == PC) @@ -772,6 +774,9 @@ classify_insn (rtx x) return CALL_INSN; if (has_return_p) return JUMP_INSN; + if (GET_CODE (XVECEXP (x, 0, 0)) == ASM_OPERANDS + && ASM_OPERANDS_LABEL_VEC (XVECEXP (x, 0, 0))) + return JUMP_INSN; } #ifdef GENERATOR_FILE if (GET_CODE (x) == MATCH_OPERAND --- gcc/emit-rtl.c.jj 2019-01-10 11:43:14.388377679 +0100 +++ gcc/emit-rtl.c 2019-04-22 16:25:08.698982786 +0200 @@ -3940,6 +3940,7 @@ try_split (rtx pat, rtx_insn *trial, int break; case REG_NON_LOCAL_GOTO: + case REG_LABEL_TARGET: for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn)) { if (JUMP_P (insn)) --- gcc/testsuite/gcc.target/i386/pr90193.c.jj 2019-04-22 16:28:06.554127408 +0200 +++ gcc/testsuite/gcc.target/i386/pr90193.c 2019-04-22 16:27:45.644463104 +0200 @@ -0,0 +1,21 @@ +/* PR target/90193 * +/* { dg-do link } */ +/* { dg-options "-O1" } */ +/* { dg-require-effective-target tls } */ + +__thread int var; + +static int +foo (void) +{ + asm goto ("jmp %l[l]\n\t" : : "m" (var) : : l); + return 0; +l: + return 1; +} + +int +main () +{ + return foo (); +} Jakub