http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53433
--- Comment #21 from Uros Bizjak <ubizjak at gmail dot com> 2012-07-04 10:10:13 UTC --- It looks that expand_builtin_strncmp gets miscompiled. Try to compile the testcase from Comment #5 with -O2 on x86_64-pc-linux-gnu. Put breakpoint in gen_cmpstrnsi. When debugging "normal", non-LTO, non-profiled build, we get: Breakpoint 1, gen_cmpstrnsi (operand0=0x7ffff1ace8a0, operand1=0x7ffff1acb8b8, operand2=0x7ffff1acb918, operand3=0x7ffff19a84f0, operand4=0x7ffff19a8480) at ../../gcc-svn/trunk/gcc/config/i386/i386.md:15989 15989 (set (match_operand:P 0 "register_operand" "=D") (gdb) bt #0 gen_cmpstrnsi (operand0=0x7ffff1ace8a0, operand1=0x7ffff1acb8b8, operand2=0x7ffff1acb918, operand3=0x7ffff19a84f0, operand4=0x7ffff19a8480) at ../../gcc-svn/trunk/gcc/config/i386/i386.md:15989 #1 0x00000000005bb0c0 in expand_builtin_strncmp (exp=0x7ffff1acdd20, target=0x7ffff1ace8a0, mode=<optimized out>) at ../../gcc-svn/trunk/gcc/builtins.c:4000 (gdb) up #1 0x00000000005bb0c0 in expand_builtin_strncmp (exp=0x7ffff1acdd20, target=0x7ffff1ace8a0, mode=<optimized out>) at ../../gcc-svn/trunk/gcc/builtins.c:4000 4000 GEN_INT (MIN (arg1_align, arg2_align))); (gdb) li 3995 3996 arg1_rtx = get_memory_rtx (arg1, len); 3997 arg2_rtx = get_memory_rtx (arg2, len); 3998 arg3_rtx = expand_normal (len); 3999 insn = gen_cmpstrnsi (result, arg1_rtx, arg2_rtx, arg3_rtx, 4000 GEN_INT (MIN (arg1_align, arg2_align))); 4001 if (insn) 4002 { 4003 emit_insn (insn); 4004 (gdb) p target $11 = (rtx_def *) 0x7ffff1ace8a0 (gdb) p result $12 = (rtx_def *) 0x7ffff1ace8a0 (gdb) debugging profiledbootstrap (--with-build-config=bootstrap-lto): Breakpoint 3, gen_cmpstrnsi (operand0=0x7ffff1ace9e0, operand1=0x7ffff1acb8b8, operand2=0x7ffff1acb918, operand3=0x7ffff19a84f0, operand4=0x7ffff19a8480) at ../../gcc-svn/trunk/gcc/config/i386/i386.md:15989 15989 (set (match_operand:P 0 "register_operand" "=D") (gdb) bt #0 gen_cmpstrnsi (operand0=0x7ffff1ace9e0, operand1=0x7ffff1acb8b8, operand2=0x7ffff1acb918, operand3=0x7ffff19a84f0, operand4=0x7ffff19a8480) at ../../gcc-svn/trunk/gcc/config/i386/i386.md:15989 #1 0x0000000000b3310f in _ZL22expand_builtin_strncmpP9tree_nodeP7rtx_def12machine_mode.isra.13 ( target=0x7ffff1ace8a0, exp=0x7ffff1acdd20) at ../../gcc-svn/trunk/gcc/builtins.c:4000 (gdb) p target $12 = (struct rtx_def *) 0x7ffff1ace8a0 (gdb) p result $13 = '\000' <repeats 113 times> (gdb) The trick is that a couple of lines above, we have: /* Make a place to write the result of the instruction. */ result = target; if (! (result != 0 && REG_P (result) && GET_MODE (result) == insn_mode && REGNO (result) >= FIRST_PSEUDO_REGISTER)) result = gen_reg_rtx (insn_mode); Probably "result" doesn't get propagated correctly to gen_cmpstrnsi, we have: (gdb) p *target $15 = {code = REG, mode = SImode, jump = 0, call = 0, unchanging = 0, volatil = 0, in_struct = 0, (gdb) down #0 gen_cmpstrnsi (operand0=0x7ffff1ace9e0, operand1=0x7ffff1acb8b8, operand2=0x7ffff1acb918, operand3=0x7ffff19a84f0, operand4=0x7ffff19a8480) at ../../gcc-svn/trunk/gcc/config/i386/i386.md:15989 15989 (set (match_operand:P 0 "register_operand" "=D") (gdb) p *operand0 $14 = {code = REG, mode = VOIDmode, jump = 0, call = 0, unchanging = 0, volatil = 0, in_struct = 0, Everything goes downhill there. (sorry for not using debug_rtx here, calling it gdb says "Cannot resolve function debug_rtx to any overloaded instance".)