[Patch] The comparison in a compare exchange should not take place in VOIDmode

James Greenhalgh james.greenhalgh@arm.com
Thu Jun 4 14:25:00 GMT 2015


Hi,

I was playing with some changes to costs for some immediate values in
AArch64, and ended up tripping an ICE in some builtin expansion code.

The ICE looked like this (some pruning of the boring bits...)

format.c: In function '_gfortran_caf_atomic_cas':
format.c:13:3: internal compiler error: in int_mode_for_mode, at stor-layout.c:443
   (void)__atomic_compare_exchange_n(atom, (uint32_t *)old, *(uint32_t *)new_val,
   ^
0xa5e2b0 int_mode_for_mode(machine_mode)
	/work/gcc-dev/src/gcc/gcc/stor-layout.c:443
0x74cd78 emit_move_via_integer
	/work/gcc-dev/src/gcc/gcc/expr.c:3174
   ...  <snip>
0x73e5cf force_reg(machine_mode, rtx_def*)
	/work/gcc-dev/src/gcc/gcc/explow.c:643
0x997458 prepare_cmp_insn
	/work/gcc-dev/src/gcc/gcc/optabs.c:4076
   ...  <snip>

0x63e4cf expand_builtin_atomic_compare_exchange
	/work/gcc-dev/src/gcc/gcc/builtins.c:5479
   ...  <snip>

The final symptom can be seen in force_reg, where it is asked to provide

  (set:VOID
    (reg:SI) (const_int 0))

And gives up. We end up here, as prepare_cmp_insn tries to force "expensive"
constants to a register, using the mode provided to it from further up
the call stack...

Which takes us to expand_builtin_atomic_compare_exchange, which
explicitly uses a VOIDmode for the comparison. This looks wrong to
me, is a VOIDmode comparison ever valid?

This patch fixes the issue by performing the comparison in the mode
of the cmp-exchange target. It seems sensible to me, but may be
nonsense, so I defer to others' opinions.

Bootstrapped on AArch64/x86_64.

OK?

Thanks,
James

---
2015-06-04  James Greenhalgh  <james.greenhalgh@arm.com>

	* builtins.c (expand_builtin_atomic_compare_exchange): Call
	emit_cmp_and_jump_insns with the mode of target.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Patch-The-comparison-in-a-compare-exchange-should-no.patch
Type: text/x-patch
Size: 602 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150604/f66f4e05/attachment.bin>


More information about the Gcc-patches mailing list