[Bug c/99155] redundant AND instructions generated to mask bit fields

2021-02-18 Thread dennisc at harding dot ca via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99155

--- Comment #2 from Dennis Cote  ---
Ah, I see. So the default does no optimization at all, not even redundant
instruction elimination. Even -O1 completely inlines the function to 3 MOV
instructions with constant values. So I have learned to always turn on some
optimizations. Thanks for the quick follow-up.

[Bug c/99155] New: redundant AND instructions generated to mask bit fields

2021-02-18 Thread dennisc at harding dot ca via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99155

Bug ID: 99155
   Summary: redundant AND instructions generated to mask bit
fields
   Product: gcc
   Version: 10.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dennisc at harding dot ca
  Target Milestone: ---

Created attachment 50217
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50217=edit
C source file and Compiler Explorer screen capture

While looking at some code on Compiler Explorer I noticed that GCC 10.2 was
producing suboptimal code compared to MSVC 19.0. I saw that GCC was issuing
redundant AND instructions to mask off bit fields in my C code.

I have attached the short C source file used for the test and a screen capture
of the Compiler Explorer output from GCC 10.2 and MSVC 19.0 in a ZIP file. I
don't think this Compiler Explorer share URL will survive but in case it does
you can try https://godbolt.org/z/hhaov9

The assignment at source line 68 generates code at line 15-22 for GCC which
contains two redundant AND instructions at lines 16-17. This can be compared to
the MSVC code at lines 22-27 which contains an equivalent single AND at line
23.

The same issue is repeated at lines 24-25 corresponding to source line 69, and
lines 33-34 corresponding to source line 70.

[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-26 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-26 18:40 ---
(From update of attachment 7387)
The ICE is triggered by the char function return value assignment when
compiling for the Renesas ABI.


-- 
   What|Removed |Added

   Attachment #7387|preprocessed 6line file that|preprocessed 6 line file
description|triggers ICE|that triggers ICE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-26 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-26 18:45 ---
I was premature in reporting that version 3.4.2 fixed this bug. I didn't get a
ICE on my test file anymore, but not because the bug was fixed. It turns out
that version 3.4.2 compilers ignore the -mrenesas target option and always
generate code for the standard ABI. This additional bug hid the orginal problem
since it only occurs when using the renesas ABI. 

-- 
   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
  Known to work|3.4.2   |
 Resolution|FIXED   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-26 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-26 18:52 ---
I have found a patch for this problem that was proposed by DJ Delorie about a
year ago. His posting in the mailing list is at
http://gcc.gnu.org/ml/gcc-patches/2003-10/msg02277.html which I have copied below.

* From: DJ Delorie dj at redhat dot com
* To: gcc-patches at gcc dot gnu dot org
* Cc: dj at redhat dot com
* Date: Fri, 24 Oct 2003 23:10:31 -0400
* Subject: [patch] sh-elf, -mrenesas, FUNCTION_VALUE

This file:

char bar(int);

void foo (char *f, int i)
{
  f[i] = bar(i);
}

Fails thusly:

$ ./cc1 -quiet -mrenesas -O2 -m4 dj.c
dj.c: In function `foo':

dj.c:5: internal compiler error: in emit_move_insn, at expr.c:2792


The failure is due to bar()'s return value being mispromoted, leading
to a (set (QI) (SI)).  Proposed patch follows.  Comments?


2003-10-24  DJ Delorie  [EMAIL PROTECTED]

* config/sh/sh.h (FUNCTION_VALUE): Support renesas attribute.

Index: config/sh/sh.h
===
RCS file: /cvs/gcc/gcc/gcc/config/sh/sh.h,v
retrieving revision 1.225
diff -p -2 -r1.225 sh.h
*** config/sh/sh.h  13 Oct 2003 21:16:32 -  1.225
--- config/sh/sh.h  25 Oct 2003 02:35:39 -
*** extern enum reg_class reg_class_from_let
*** 1634,1646 
  #define FUNCTION_VALUE(VALTYPE, FUNC) \
gen_rtx (REG,   \
!  ((GET_MODE_CLASS (TYPE_MODE (VALTYPE)) == MODE_INT   \
! GET_MODE_SIZE (TYPE_MODE (VALTYPE))  UNITS_PER_WORD\
! (TREE_CODE (VALTYPE) == INTEGER_TYPE\
!|| TREE_CODE (VALTYPE) == ENUMERAL_TYPE\
!|| TREE_CODE (VALTYPE) == BOOLEAN_TYPE \
!|| TREE_CODE (VALTYPE) == CHAR_TYPE\
!|| TREE_CODE (VALTYPE) == REAL_TYPE\
!|| TREE_CODE (VALTYPE) == OFFSET_TYPE))\
!   ? (TARGET_SHMEDIA ? DImode : SImode) : TYPE_MODE (VALTYPE)), \
   BASE_RETURN_VALUE_REG (TYPE_MODE (VALTYPE)))
  
--- 1634,1648 
  #define FUNCTION_VALUE(VALTYPE, FUNC) \
gen_rtx (REG,   \
!sh_attr_renesas_p (FUNC)   \
!  ? TYPE_MODE (VALTYPE)\
!  : ((GET_MODE_CLASS (TYPE_MODE (VALTYPE)) == MODE_INT \
!   GET_MODE_SIZE (TYPE_MODE (VALTYPE))  UNITS_PER_WORD  \
!   (TREE_CODE (VALTYPE) == INTEGER_TYPE  \
!  || TREE_CODE (VALTYPE) == ENUMERAL_TYPE  \
!  || TREE_CODE (VALTYPE) == BOOLEAN_TYPE   \
!  || TREE_CODE (VALTYPE) == CHAR_TYPE  \
!  || TREE_CODE (VALTYPE) == REAL_TYPE  \
!  || TREE_CODE (VALTYPE) == OFFSET_TYPE))  \
! ? (TARGET_SHMEDIA ? DImode : SImode) : TYPE_MODE (VALTYPE)), \
   BASE_RETURN_VALUE_REG (TYPE_MODE (VALTYPE)))


I'm not really able to judge the nature of the patch, but I will test it as soon
as I can get GCC version 3.4.2 to recognize the -mrenesas switch again.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-20 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-20 18:04 ---
Created an attachment (id=7387)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7387action=view)
preprocessed 6line file that triggers ICE

This is the preprocessor output of a minimal (6 line) file that triggers the
ICE.

-- 
   What|Removed |Added

Attachment #7232 is|0   |1
   obsolete||
Attachment #7233 is|0   |1
   obsolete||


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-20 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-20 18:06 ---
Created an attachment (id=7388)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7388action=view)
gcc command and output for minimal test

This is the command line and compiler output produce with the new minimal
trigger file.

This file will compile if the command line option -mrenesas is removed.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-20 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-20 18:49 ---
This bug is triggered by calls to functions that return a char value combined
with the -mrenesas compiler option. Removing the compiler option, or changing
the functions return type to int will both eliminate the error. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-20 Thread dennisc at harding dot ca

--- Additional Comments From dennisc at harding dot ca  2004-10-20 22:17 ---
I have requilt my cross compiler using the latest GCC 3.4.2 source and the bug
is gone. It compiles the same test case code without the ICE. 

This bug can probably be closed now. Good job.

-- 
   What|Removed |Added

  Known to fail||3.4.0
  Known to work||3.4.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717


[Bug target/17717] SH4 internal compiler error: in emit_move_insn

2004-10-13 Thread dennisc at harding dot ca


-- 
   What|Removed |Added

   Attachment #7232|preprocessed source for |preprocessed source for
description|first inteernal error case  |first internal error case


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17717