This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix builtin-arith-overflow-p-1[23].c on i686


Hi!

On the builtin-arith-overflow-p-1{2,3}.c testcases (posted earlier today)
i?86 miscompiles e.g. t111_4mul function.  Before peephole2 we have:
(insn 9 6 50 2 (parallel [
            (set (reg:CCO 17 flags)
                (eq:CCO (mult:DI (sign_extend:DI (reg/v:SI 0 ax [orig:90 x ] [90]))
                        (const_int -1073741824 [0xffffffffc0000000]))
                    (sign_extend:DI (mult:SI (reg/v:SI 0 ax [orig:90 x ] [90])
                            (const_int -1073741824 [0xffffffffc0000000])))))
            (set (reg:SI 1 dx [91])
                (mult:SI (reg/v:SI 0 ax [orig:90 x ] [90])
                    (const_int -1073741824 [0xffffffffc0000000])))
        ]) builtin-arith-overflow-p-12.i:35 326 {*mulvsi4_1}
     (expr_list:REG_UNUSED (reg:SI 1 dx [91])
        (nil)))

(insn 50 9 51 2 (set (reg:QI 1 dx [orig:89 _5+4 ] [89])
        (eq:QI (reg:CCO 17 flags)
            (const_int 0 [0]))) builtin-arith-overflow-p-12.i:35 631 {*setcc_qi}
     (expr_list:REG_DEAD (reg:CCO 17 flags)
        (nil)))

(insn 51 50 16 2 (set (reg:SI 1 dx [orig:89 _5+4 ] [89])
        (zero_extend:SI (reg:QI 1 dx [orig:89 _5+4 ] [89]))) builtin-arith-overflow-p-12.i:35 130 {*zero_extendqisi2}
     (nil))

and the setcc+movzbl peephole ignores the dx = ax * -1073741824
SET in the PARALLEL, because it isn't a CLOBBER and thus initializes
%edx before insn 9, then insn 9 overwrites it and later on we store
the QImode part, assuming the rest is zero.
Fixed by using reg_set_p, to actually test if the operands[3] REG
is SET or CLOBBERed.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-06-15  Jakub Jelinek  <jakub@redhat.com>

	* config/i386/i386.md (setcc + movzbl peephole2): Use reg_set_p.

--- gcc/config/i386/i386.md.jj	2016-06-14 21:38:40.000000000 +0200
+++ gcc/config/i386/i386.md	2016-06-15 18:56:41.405559224 +0200
@@ -11849,8 +11849,7 @@ (define_peephole2
   "(peep2_reg_dead_p (3, operands[1])
     || operands_match_p (operands[1], operands[3]))
    && ! reg_overlap_mentioned_p (operands[3], operands[0])
-   && ! (GET_CODE (operands[4]) == CLOBBER
-	 && reg_mentioned_p (operands[3], operands[4]))"
+   && ! reg_set_p (operands[3], operands[4])"
   [(parallel [(set (match_dup 5) (match_dup 0))
 	      (match_dup 4)])
    (set (strict_low_part (match_dup 6))

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]