https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129052
--- Comment #7 from Hongtao Liu <liuhongt at gcc dot gnu.org> --- Created attachment 66355 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66355&action=edit Fix the hang, on top of attachment 66349 The patch in comment #5 fixes the testcase, but with it this one hangs in x86_cse at -O2 -fPIC (trunk without the patch miscompiles it the same way as the original testcase): __thread int t; void g (int *); void f (long a, long b, int c) { register long r9 asm ("r9") = a; register long r8 asm ("r8"); asm ("" : "+r" (r9)); asm goto ("" :::: out); r8 = b; asm ("" :: "r" (r9)); if (c) { asm ("" :: "r" (r8)); g (&t); } else { asm ("" :: "r" (r8)); t = 0; } out:; } In the block after the asm goto, r8 is now tracked and is still live at the jcc, so we take the JUMP_P path: bb = ix86_get_dominator_for_reg (FLAGS_REG, bb); The only FLAGS setter dominating bb is the compare in bb itself, so this returns bb and we start over on the same block forever. Since the call can't be placed at or after the jump, the jump can just end the scan and go through the same code as the end of the block. A FLAGS set in bb then needs to count as a local def, so that it moves to the immediate dominator. The attached patch (on top of attachment 66349) does that by folding ix86_check_flags_reg into the new note_stores callback. It also skips CLOBBERs there, as ix86_check_flags_reg did: explicit clobbers on call insns never get a REG_UNUSED note, so they would stay live to the end of the block. With it, both the PR testcase and the one above get correct code; for the one above, the call now goes before both register assignments. The TLS tests in gcc.dg/tls and gcc.target/i386 show no asm change at -O1/-O2 with -mtls-dialect=gnu and gnu2.
