--- gcc/config/i386.c 2018/04/24 17:54:06 1.1.1.2 +++ gcc/config/i386.c 2018/04/24 17:59:01 1.1.1.3 @@ -45,6 +45,7 @@ extern char *strcat (); char *singlemove_string (); char *output_move_const_single (); +char *output_fp_cc0_set (); static char *hi_reg_name[] = HI_REGISTER_NAMES; static char *qi_reg_name[] = QI_REGISTER_NAMES; @@ -65,6 +66,12 @@ enum reg_class regclass_map[FIRST_PSEUDO /* arg pointer */ INDEX_REGS }; + +/* Test and compare insns in i386.md store the information needed to + generate branch and scc insns here. */ + +struct rtx_def *i386_compare_op0, *i386_compare_op1; +struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)(); /* Output an insn whose source is a 386 integer register. SRC is the rtx for the register, and TEMPLATE is the op-code template. SRC may @@ -614,6 +621,8 @@ function_prologue (file, size) register int regno; int limit; rtx xops[4]; + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); xops[0] = stack_pointer_rtx; xops[1] = frame_pointer_rtx; @@ -639,14 +648,13 @@ function_prologue (file, size) limit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); for (regno = limit - 1; regno >= 0; regno--) if ((regs_ever_live[regno] && ! call_used_regs[regno]) - || (current_function_uses_pic_offset_table - && regno == PIC_OFFSET_TABLE_REGNUM)) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) { xops[0] = gen_rtx (REG, SImode, regno); output_asm_insn ("push%L0 %0", xops); } - if (current_function_uses_pic_offset_table) + if (pic_reg_used) { xops[0] = pic_offset_table_rtx; xops[1] = (rtx) gen_label_rtx (); @@ -675,6 +683,8 @@ simple_386_epilogue () int nregs = 0; int reglimit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); #ifdef NON_SAVING_SETJMP if (NON_SAVING_SETJMP && current_function_calls_setjmp) @@ -686,8 +696,7 @@ simple_386_epilogue () for (regno = reglimit - 1; regno >= 0; regno--) if ((regs_ever_live[regno] && ! call_used_regs[regno]) - || (current_function_uses_pic_offset_table - && regno == PIC_OFFSET_TABLE_REGNUM)) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) nregs++; return nregs == 0 || ! frame_pointer_needed; @@ -706,6 +715,8 @@ function_epilogue (file, size) register int nregs, limit; int offset; rtx xops[3]; + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); /* Compute the number of registers to pop */ @@ -717,8 +728,7 @@ function_epilogue (file, size) for (regno = limit - 1; regno >= 0; regno--) if ((regs_ever_live[regno] && ! call_used_regs[regno]) - || (current_function_uses_pic_offset_table - && regno == PIC_OFFSET_TABLE_REGNUM)) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) nregs++; /* sp is often unreliable so we must go off the frame pointer, @@ -744,8 +754,7 @@ function_epilogue (file, size) for (regno = 0; regno < limit; regno++) if ((regs_ever_live[regno] && ! call_used_regs[regno]) - || (current_function_uses_pic_offset_table - && regno == PIC_OFFSET_TABLE_REGNUM)) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) { xops[0] = gen_rtx (REG, SImode, regno); output_asm_insn ("pop%L0 %0", xops); @@ -754,8 +763,7 @@ function_epilogue (file, size) else for (regno = 0; regno < limit; regno++) if ((regs_ever_live[regno] && ! call_used_regs[regno]) - || (current_function_uses_pic_offset_table - && regno == PIC_OFFSET_TABLE_REGNUM)) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) { xops[0] = gen_rtx (REG, SImode, regno); xops[1] = adj_offsettable_operand (AT_BP (Pmode), offset); @@ -975,8 +983,6 @@ print_operand (file, x, code) putc ('*', file); return; - case 'D': - PUT_OP_SIZE (code, 'l', file); case 'L': PUT_OP_SIZE (code, 'l', file); return; @@ -997,10 +1003,6 @@ print_operand (file, x, code) PUT_OP_SIZE (code, 's', file); return; - case 'R': - fprintf (file, "%s", RP); - return; - case 'z': /* 387 opcodes don't get size suffixes if the operands are registers. */ @@ -1031,11 +1033,29 @@ print_operand (file, x, code) case 8: if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT) - PUT_OP_SIZE ('Q', 'l', file); + { +#ifdef GAS_MNEMONICS + PUT_OP_SIZE ('Q', 'q', file); + return; +#else + PUT_OP_SIZE ('Q', 'l', file); /* Fall through */ +#endif + } PUT_OP_SIZE ('Q', 'l', file); return; } + + case 'b': + case 'w': + case 'k': + case 'h': + case 'y': + case 'P': + break; + + default: + abort (); } } if (GET_CODE (x) == REG) @@ -1062,13 +1082,8 @@ print_operand (file, x, code) u.i[0] = CONST_DOUBLE_LOW (x); u.i[1] = CONST_DOUBLE_HIGH (x); u1.f = u.d; - if (code == 'f') - fprintf (file, "%.22e", u1.f); - else - { - PRINT_IMMED_PREFIX (file); - fprintf (file, "0x%x", u1.i); - } + PRINT_IMMED_PREFIX (file); + fprintf (file, "0x%x", u1.i); } else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) { @@ -1079,9 +1094,9 @@ print_operand (file, x, code) } else { - if (code != 'c' && code != 'P') + if (code != 'P') { - if (GET_CODE (x) == CONST_INT) + if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) PRINT_IMMED_PREFIX (file); else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF) @@ -1352,6 +1367,8 @@ notice_update_cc (exp) CC_STATUS_INIT; if (! stack_regs_mentioned_p (SET_SRC (XVECEXP (exp, 0, 0)))) cc_status.value1 = SET_SRC (XVECEXP (exp, 0, 0)); + + cc_status.flags |= CC_IN_80387; return; } CC_STATUS_INIT; @@ -1678,7 +1695,8 @@ output_fix_trunc (insn, operands) /* Output code for INSN to compare OPERANDS. The two operands might not have the same mode: one might be within a FLOAT or FLOAT_EXTEND - expression. */ + expression. If the compare is in mode CCFPEQmode, use an opcode that + will not fault if a qNaN is present. */ char * output_float_compare (insn, operands) @@ -1686,6 +1704,8 @@ output_float_compare (insn, operands) rtx *operands; { int stack_top_dies; + rtx body = XVECEXP (PATTERN (insn), 0, 0); + int unordered_compare = GET_MODE (SET_SRC (body)) == CCFPEQmode; if (! STACK_TOP_P (operands[0])) abort (); @@ -1701,15 +1721,21 @@ output_float_compare (insn, operands) is also a stack register that dies, then this must be a `fcompp' float compare */ - output_asm_insn ("fcompp", operands); + if (unordered_compare) + output_asm_insn ("fucompp", operands); + else + output_asm_insn ("fcompp", operands); } else { static char buf[100]; - /* Decide if this is the integer or float compare opcode. */ + /* Decide if this is the integer or float compare opcode, or the + unordered float compare. */ - if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_FLOAT) + if (unordered_compare) + strcpy (buf, "fucom"); + else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_FLOAT) strcpy (buf, "fcom"); else strcpy (buf, "ficom"); @@ -1727,10 +1753,102 @@ output_float_compare (insn, operands) /* Now retrieve the condition code. */ - output_asm_insn (AS1 (fnsts%W2,%2), operands); + return output_fp_cc0_set (insn); +} + +/* Output opcodes to transfer the results of FP compare or test INSN + from the FPU to the CPU flags. If TARGET_IEEE_FP, ensure that if the + result of the compare or test is unordered, no comparison operator + succeeds except NE. Return an output template, if any. */ + +char * +output_fp_cc0_set (insn) + rtx insn; +{ + rtx xops[3]; + rtx unordered_label; + rtx next; + enum rtx_code code; + + xops[0] = gen_rtx (REG, HImode, 0); + output_asm_insn (AS1 (fnsts%W0,%0), xops); + + if (! TARGET_IEEE_FP) + return "sahf"; + + next = next_cc0_user (insn); - cc_status.flags |= CC_IN_80387; - return "sahf"; + if (GET_CODE (next) == JUMP_INSN + && GET_CODE (PATTERN (next)) == SET + && SET_DEST (PATTERN (next)) == pc_rtx + && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE) + { + code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0)); + } + else if (GET_CODE (PATTERN (next)) == SET) + { + code = GET_CODE (SET_SRC (PATTERN (next))); + } + else + abort (); + + xops[0] = gen_rtx (REG, QImode, 0); + + switch (code) + { + case GT: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x45); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + /* je label */ + break; + + case LT: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x45); + xops[2] = gen_rtx (CONST_INT, VOIDmode, 0x01); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* je label */ + break; + + case GE: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x05); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + /* je label */ + break; + + case LE: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x45); + xops[2] = gen_rtx (CONST_INT, VOIDmode, 0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS1 (dec%B0,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* jb label */ + break; + + case EQ: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x45); + xops[2] = gen_rtx (CONST_INT, VOIDmode, 0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* je label */ + break; + + case NE: + xops[1] = gen_rtx (CONST_INT, VOIDmode, 0x44); + xops[2] = gen_rtx (CONST_INT, VOIDmode, 0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (xor%B0,%2,%h0), xops); + /* jne label */ + break; + + case GTU: + case LTU: + case GEU: + case LEU: + default: + abort (); + } + RET; } #ifdef HANDLE_PRAGMA @@ -1787,7 +1905,7 @@ handle_pragma_token (string, token) fputc ('\n', asm_out_file); if (state == ps_value) { - fprintf (asm_out_file, "\t%s\t", DEF_ASM_OP); + fprintf (asm_out_file, "\t%s\t", SET_ASM_OP); ASM_OUTPUT_LABELREF (asm_out_file, name); fputc (',', asm_out_file); ASM_OUTPUT_LABELREF (asm_out_file, value);