This is the mail archive of the gcc-bugs@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]

[Bug hsa/82416] Miscompilation due to HSA BE expanding all sub-integer types to integer types


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82416

--- Comment #1 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Created attachment 42308
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42308&action=edit
Fix

This is a fix I have come up with so far.  The key change is the
simple flip from true to false in
hsa_function_representation::reg_for_gimple_ssa, everything else is
there to compensate the big impact that has.

Basically, until the time we really output them, registers keep the
type of the data that they hold and we extend them whenever we want
perform on them any computation that can only be done in at least 32
bits in HSA, which is almost all of them - and then we convert them
back to a shorter type if necessary.

The only exception are complex numbers because combine/expand also
only exist in 32bits which in theory might break like the testcase
does when someone does something similar with a complex char... but
hopefully gimple does not perform such optimization on complex
numbers.  If it turns out it does, I guess we'll refuse to generate
HSA for them.

Pekka, can you try if this works for you as well?  I plan to commit
this early next week after a tiny bit more testing.

2017-10-04  Martin Jambor  <mjambor@suse.cz>

        PR hsa/82416
gcc/
        * hsa-common.h (hsa_op_with_type): New method extend_int_to_32bit.
        * hsa-gen.c (hsa_extend_inttype_to_32bit): New function.
        (hsa_type_for_scalar_tree_type): Use it.  Always force min32int for
        COMPLEX types.
        (hsa_fixup_mov_insn_type): New function.
        (hsa_op_with_type::get_in_type): Use it.
        (hsa_build_append_simple_mov): Likewise.  Allow sub-32bit
        immediates in an assert.
        (hsa_op_with_type::extend_int_to_32bit): New method.
        (gen_hsa_insns_for_bitfield): Fixup instruction and intermediary
        types.  Convert to dest type if necessary.
        (gen_hsa_insns_for_bitfield_load): Fixup load type if necessary.
        (reg_for_gimple_ssa): Pass false as min32int to
        hsa_type_for_scalar_tree_type.
        (gen_hsa_addr): Fixup type when creating addresable temporary.
        (gen_hsa_cmp_insn_from_gimple): Extend operands if necessary.
        (gen_hsa_unary_operation): Extend operands and convert to dest type if
        necessary.  Call hsa_fixup_mov_insn_type.
        (gen_hsa_binary_operation): Changed operand types to hsa_op_with_type,
        extend operands and convert to dest type if necessary.
        (gen_hsa_insns_for_operation_assignment): Extend operands and convert
        to dest type if necessary.
        (set_output_in_type): Call hsa_fixup_mov_insn_type.  Just ude dest
        if conversion nt necessary and size matches.
        (gen_hsa_insns_for_load): Call hsa_fixup_mov_insn_type, convert
        to dest type if necessary.
        (gen_hsa_insns_for_store): Call hsa_fixup_mov_insn_type.
        (gen_hsa_insns_for_switch_stmt): Likewise. Also extend operands if
        necessary.
        (gen_hsa_clrsb): Likewise.
        (gen_hsa_ffs): Likewise.
        (gen_hsa_divmod): Extend operands and convert to dest type if
        necessary.
        (gen_hsa_atomic_for_builtin): Change type of op to hsa_op_with_type.

libgomp/
        * testsuite/libgomp.hsa.c/pr82416.c: New test.

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