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 ubsan expansion of multiplication (PR rtl-optimization/60030)


Hi!

ubsan/overflow-1.c test ICEs on ppc32, because lopart is SImode, and we
attempt to do a DImode left shift on it by 32.
We don't really care about the upper bits, those are all shifted away
anyway, so this patch fixes it by adding a paradoxical SUBREG, which results
in better generated code compared to e.g. adding there a ZERO_EXTEND.

Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested
with ubsan tests on x86_64 and i686 with the add/sub/mul/neg with overflow
patterns disabled and tested using ppc* cross on overflow-1.c.

Ok for trunk?

2014-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/60030
	* internal-fn.c (ubsan_expand_si_overflow_mul_check): Surround
	lopart with paradoxical subreg before shifting it up by hprec.

--- gcc/internal-fn.c.jj	2014-01-29 12:43:24.000000000 +0100
+++ gcc/internal-fn.c	2014-02-03 10:40:57.000000000 +0100
@@ -646,7 +646,8 @@ ubsan_expand_si_overflow_mul_check (gimp
 	    emit_cmp_and_jump_insns (hipart, const0_rtx, GE, NULL_RTX, hmode,
 				     false, after_hipart_neg, PROB_EVEN);
 
-	  tem = expand_shift (LSHIFT_EXPR, mode, lopart, hprec, NULL_RTX, 1);
+	  tem = gen_rtx_SUBREG (mode, lopart, 0);
+	  tem = expand_shift (LSHIFT_EXPR, mode, tem, hprec, NULL_RTX, 1);
 	  tem = expand_simple_binop (mode, MINUS, loxhi, tem, NULL_RTX,
 				     1, OPTAB_DIRECT);
 	  emit_move_insn (loxhi, tem);

	Jakub


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