[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-13 Thread law at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #7 from Jeffrey A. Law  ---
*** Bug 58401 has been marked as a duplicate of this bug. ***


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-13 Thread law at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

Jeffrey A. Law  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2013-09-13
 Ever confirmed|0   |1


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-13 Thread law at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #6 from Jeffrey A. Law  ---
Reduced testcase:
static __inline__ __attribute__((always_inline))
__attribute__((no_instrument_function)) int test_bit(int nr, const unsigned
long* addr)
{
 return (*((volatile unsigned char *)addr +
   ((nr >> 3) ^ 3)) & (1UL << (nr & 7))) != 0;
}
static inline __attribute__((always_inline))
__attribute__((no_instrument_function)) int test_bit_le(int nr, const void
*addr)
{
 return test_bit(nr ^ ((32 -1) & ~0x7), addr);
}
typedef int ext4_grpblk_t;
struct ext4_group_info {
 unsigned long bb_state;
 ext4_grpblk_t bb_counters[];
};
struct ext4_buddy {
 struct super_block *bd_sb;
 struct ext4_group_info *bd_info;
};
static inline __attribute__((always_inline))
__attribute__((no_instrument_function)) void *mb_correct_addr_and_bit(int *bit,
void *addr)
{
 *bit += ((unsigned long) addr & 3UL) << 3;
 return addr;
}
static inline __attribute__((always_inline))
__attribute__((no_instrument_function)) int mb_test_bit(int bit, void *addr)
{
 addr = mb_correct_addr_and_bit(&bit, addr);
 return test_bit_le(bit, addr);
}
static inline __attribute__((always_inline))
__attribute__((no_instrument_function)) void mb_clear_bit(int bit, void *addr)
{
 addr = mb_correct_addr_and_bit(&bit, addr);
 __clear_bit_le(bit, addr);
}
static inline __attribute__((always_inline))
__attribute__((no_instrument_function)) int mb_buddy_adjust_border(int* bit,
void* bitmap, int side)
{
 if (mb_test_bit(*bit + side, bitmap)) {
  mb_clear_bit(*bit, bitmap);
 }
}
static void mb_buddy_mark_free(struct ext4_buddy *e4b, int first)
{
 int max;
 int order = 1;
 void *buddy = bar ();
 while (buddy) {
  void *buddy2;
   e4b->bd_info->bb_counters[order] += mb_buddy_adjust_border(&first, buddy,
-1);
  order++;
  buddy = buddy2;
 }
}
void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
  int first, int count)
{
 int last = first + count - 1;
 int block;
 struct super_block *sb = e4b->bd_sb;
 block = foo();
 if (!!(block != -1)) 
  mb_regenerate_buddy();
 mb_buddy_mark_free(e4b, first >> 1);
}


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-13 Thread law at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

Jeffrey A. Law  changed:

   What|Removed |Added

 CC||kazu at gcc dot gnu.org,
   ||law at redhat dot com

--- Comment #5 from Jeffrey A. Law  ---
Kazu, you added these patterns many years ago...  Your thoughts would be
appreciated.

Compile the attached code with -O2 -mh -mint32 on the H8 port, using the trunk.

It'll fail due to an insn not matching its constraints problem.


The H8 port has the following insn:

(define_insn_and_split "*tstsi_variable_bit_qi"
  [(set (cc0)
(compare (zero_extract:SI (zero_extend:SI (match_operand:QI 0
"general_operand_src" "r,U,mn>"))
  (const_int 1)
  (and:SI (match_operand:SI 1
"register_operand" "r,r,r")
  (const_int 7)))
 (const_int 0)))
   (clobber (match_scratch:QI 2 "=X,X,&r"))]
  "TARGET_H8300H || TARGET_H8300S"
  "@
   btst\\t%w1,%X0
   btst\\t%w1,%X0
   #"
  "&& reload_completed
   && !satisfies_constraint_U (operands[0])"
  [(set (match_dup 2)
(match_dup 0))
   (parallel [(set (cc0)
   (compare (zero_extract:SI (zero_extend:SI (match_dup 2))
 (const_int 1)
 (and:SI (match_dup 1)
 (const_int 7)))
(const_int 0)))
  (clobber (scratch:QI))])]
  ""
  [(set_attr "length" "2,8,10")
   (set_attr "cc" "set_zn,set_zn,set_zn")])


Now assume that operand 0 is initially a pseudo, something like this;

(insn 50 49 51 5 (parallel [
(set (cc0)
(compare (zero_extract:SI (zero_extend:SI (reg:QI 37 [ D.1545
]))
(const_int 1 [0x1])
(and:SI (reg:SI 59 [ D.1543 ])
(const_int 7 [0x7])))
(const_int 0 [0])))
(clobber (scratch:QI))
]) j.c:36 113 {*tstsi_variable_bit_qi}
 (expr_list:REG_DEAD (reg:SI 59 [ D.1543 ])
(expr_list:REG_DEAD (reg:QI 37 [ D.1545 ])
(nil


That looks fine and good.  Now assume reg:37 doesn't get a hard reg.  reload
will replace the reg with its equivalent stack slot resulting in:


(insn 50 116 51 5 (parallel [
(set (cc0)
(compare (zero_extract:SI (zero_extend:SI (mem/c:QI (plus:SI
(reg/f:SI 6 r6)
(const_int -17 [0xffef])) [7
%sfp+-9 S1 A8]))
(const_int 1 [0x1])
(and:SI (reg:SI 3 r3)
(const_int 7 [0x7])))
(const_int 0 [0])))
(clobber (scratch:QI))
]) j.c:36 113 {*tstsi_variable_bit_qi}
 (nil))


Note that the insn no longer matches its strict constraints.  It doesn't match
alternatives 0 or 1 because of operand 0.  It doesn't match alternative 2
because the SCRATCH is not a REG.

I'm guessing you wanted reload to give you a scratch register that you could
use for generating code when operand0 wasn't a suitable source for a single bit
extraction.  You'd then split the insn at insn output time using the scratch
register to effectively reload operand0 yourself?

Note there's another pattern tst_extzv_1_n that has potentially the same
problem.

The fundamental issue is that once reload is done, all insns must always
satisfy their constraints, no exceptions. 

Thoughts on how this is supposed to work?


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-12 Thread gang.chen at asianux dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #4 from Chen Gang  ---
Created attachment 30812
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30812&action=edit
the .i file for fs/ext4/mballoc.c (bzip2 compressed)

I put .i file in attachment which need "bzip2 -d" to decompress.


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-11 Thread gang.chen at asianux dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #3 from Chen Gang  ---
If no opitimization (without -Os), it will be OK.


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-11 Thread gang.chen at asianux dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #2 from Chen Gang  ---
For gcc-4.8.0 and gcc-4.7.4, it has this issue too.


[Bug c/58400] gcc for h8300 internal compiler error: insn does not satisfy its constraints at fs/ext4/mballoc.c: In function 'mb_free_blocks':

2013-09-11 Thread gang.chen at asianux dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58400

--- Comment #1 from Chen Gang  ---
fs/ext4/mballoc.c:1459:1: internal compiler error: in
reload_cse_simplify_operands, at postreload.c:411
0x8e0a95 _fatal_insn(char const*, rtx_def const*, char const*, int, char
const*)
../../gcc-4.9.0/gcc/rtl-error.c:109
0x8e0abf _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
../../gcc-4.9.0/gcc/rtl-error.c:120
0x89be7b reload_cse_simplify_operands
../../gcc-4.9.0/gcc/postreload.c:411
0x89da9c reload_cse_simplify
../../gcc-4.9.0/gcc/postreload.c:181
0x89da9c reload_cse_regs_1
../../gcc-4.9.0/gcc/postreload.c:220
0x89deab reload_cse_regs
../../gcc-4.9.0/gcc/postreload.c:68
0x89deab rest_of_handle_postreload
../../gcc-4.9.0/gcc/postreload.c:2332
0x89deab execute
../../gcc-4.9.0/gcc/postreload.c:2368
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.
make[2]: *** [fs/ext4/mballoc.o] Error 1
make[1]: *** [fs/ext4] Error 2
make: *** [fs] Error 2


The gcc information:
[root@dhcp122 linux-next]# /usr/local/bin/h8300-gchen-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/h8300-gchen-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/h8300-gchen-elf/4.9.0/lto-wrapper
Target: h8300-gchen-elf
Configured with: ../gcc-4.9.0/configure --without-header --disable-nls
--enable-language=c,c++ --disable-threads --disable-shared --enable-werror=no
target_configargs=enable_vtable_verify=yes --target=h8300-gchen-elf
Thread model: single
gcc version 4.9.0 20130910 (experimental) (GCC)