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

            Bug ID: 90049
           Summary: Wrong expanding for a unsigned short ssa_name in
                    embedded assembly code.
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wangtao42 at huawei dot com
  Target Milestone: ---

Created attachment 46143
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46143&action=edit
testcase

A unsigned short ssa_name in embedded assembly code will be expanded to
subreg:HI, and without the bit extracting action. It will result in a wrong
assembly code.
The attachment is the testcase, and the command is as follows:
    mips-sde-elf-gcc -O2 -S t2.c

And the result assembly code is:
func:
        .frame  $sp,0,$31               # vars= 0, regs= 0/0, args= 0, gp= 0
        .mask   0x00000000,0
        .fmask  0x00000000,0
        lw      $3,0($4)
        lw      $2,%gp_rel(g_b)($28)
        srl     $4,$3,24
        sw      $3,%gp_rel(g_a)($28)
        ext     $6,$2,0,17
        sltu    $7,$4,1
 #APP
 # 27 "t2.c" 1
        addiu $5, $6, 0
movn $5, $3, $7
 # 0 "" 2
 #NO_APP
        ins     $2,$5,0,17
        .set    noreorder
        .set    nomacro
        jr      $31
        sw      $2,%gp_rel(g_b)($28)

It is wrong that the $3 is loaded a word from 0($4), and the $3 should be the
low 16bit of 0($4). I guess something wrong with expand_gimple_basic_block, and
this ignore should not be used in embedded assembly code:
5822               def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
5823
5824               if (def_p != NULL)
5825                 {
5826                   /* Ignore this stmt if it is in the list of
5827                      replaceable expressions.  */
5828                   if (SA.values
5829                       && bitmap_bit_p (SA.values,
5830                                        SSA_NAME_VERSION (DEF_FROM_PTR
(def_p))))
5831                     continue;
5832                 }
5833               last = expand_gimple_stmt (stmt);

Please help to check this.

Thanks

Reply via email to