https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66013
Bug ID: 66013 Summary: Missed optimization after inlining va_list parameter, -m32 case Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: trivial Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- [ -m32 twin PR of PR66010 ] Consider this test-case (based on gcc.dg/tree-ssa/stdarg-2.c, f15): ... #include <stdarg.h> int f1 (int i, ...) { int res; va_list ap; va_start (ap, i); res = va_arg (ap, int); va_end (ap); return res; } inline int __attribute__((always_inline)) f2_1 (va_list ap) { return va_arg (ap, int); } int f2 (int i, ...) { int res; va_list ap; va_start (ap, i); res = f2_1 (ap); va_end (ap); return res; } ... When compiling at -O2 with -m32, the optimized dump for f1 and f2 are very similar: ... # .MEM_9 = VDEF <.MEM_1(D)> # USE = anything # CLB = anything - ap_8 = __builtin_next_argD.993 (0); - ap_6 = ap_8; + ap_11 = __builtin_next_argD.993 (0); + ap_6 = ap_11; # PT = nonlocal - ap_7 = ap_6; + ap_3 = ap_6; # VUSE <.MEM_9> - res_4 = MEM[(intD.1 *)ap_7]; + _7 = MEM[(intD.1 *)ap_3]; GIMPLE_NOP # VUSE <.MEM_9> - return res_4; + return _7; ;; succ: EXIT [100.0%] ... However, at pass_stdarg, we see on one hand: ... f1: va_list escapes 0, needs to save 4 GPR units and all FPR units. ... but OTOH: ... f2: va_list escapes 1, needs to save all GPR units and all FPR units. ... Still the .s code is identical for f1 and f2: ... .cfi_startproc movl 8(%esp), %eax ret .cfi_endproc ... This is because ix86_setup_incoming_varargs doesn't do anything for -m32: ... static void ix86_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode, tree type, int *, int no_rtl) { CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); CUMULATIVE_ARGS next_cum; tree fntype; /* This argument doesn't appear to be used anymore. Which is good, because the old code here didn't suppress rtl generation. */ gcc_assert (!no_rtl); if (!TARGET_64BIT) return; ...