Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc 编译器问题 internal compiler error: in output_constructor_regular_field, at varasm.c:5512 #77

Closed
redeastcn opened this issue Jan 23, 2022 · 8 comments

Comments

@redeastcn
Copy link

loongson/build-tools#12

@xen0n
Copy link

xen0n commented Jan 26, 2022

struct Mul02Table
{
    constexpr Mul02Table() : values()
    {
        for (int s = 0; s < 4; s++) {
            values[s] = 1;
        }
    }

    unsigned char values[4];
};

static constexpr Mul02Table mul02;

native stage1 works:

$ ./prev-gcc/cc1plus -o - ~/z.cc
        .file   "z.cc"
 constexpr Mul02Table::Mul02Table() constexpr Mul02Table::Mul02Table() constexpr Mul02Table::Mul02Table()
Analyzing compilation unit
Performing interprocedural optimizations
 <*free_lang_data> {heap 896k} <visibility> {heap 896k} <build_ssa_passes> {heap 896k} <opt_local_passes> {heap 896k} <remove_symbols> {heap 896k} <targetclone> {heap 896k} <free-fnsummary> {heap 896k}Streaming LTO
 <whole-program> {heap 896k} <fnsummary> {heap 896k} <inline> {heap 896k} <modref> {heap 896k} <free-fnsummary> {heap 896k} <single-use> {heap 896k} <comdats> {heap 896k}      .text
Assembling functions:
        .section        .rodata
        .align  3
        .type   _ZL5mul02, @object
        .size   _ZL5mul02, 4
_ZL5mul02:
        .ascii  "\001\001\001\001"
        .ident  "GCC: (GNU) 12.0.0 20211224 (experimental)"
        .section        .note.GNU-stack,"",@progbits

Time variable                                   usr           sys          wall           GGC
 phase setup                        :   0.00 (  0%)   0.02 (100%)   0.02 ( 67%)  1276k ( 67%)
 phase parsing                      :   0.00 (  0%)   0.00 (  0%)   0.01 ( 33%)   627k ( 33%)
 |name lookup                       :   0.00 (  0%)   0.00 (  0%)   0.01 ( 33%)    70k (  4%)
 parser inl. meth. body             :   0.00 (  0%)   0.00 (  0%)   0.01 ( 33%)    25k (  1%)
 TOTAL                              :   0.00          0.02          0.03         1906k

native stage2 broken:

./gcc/cc1plus -o - ~/z.cc
        .file   "z.cc"
 constexpr Mul02Table::Mul02Table() constexpr Mul02Table::Mul02Table() constexpr Mul02Table::Mul02Table()
Analyzing compilation unit
Performing interprocedural optimizations
 <*free_lang_data> {heap 896k} <visibility> {heap 896k} <build_ssa_passes> {heap 896k} <opt_local_passes> {heap 896k} <remove_symbols> {heap 896k} <targetclone> {heap 896k} <free-fnsummary> {heap 896k}Streaming LTO
 <whole-program> {heap 896k} <fnsummary> {heap 896k} <inline> {heap 896k} <modref> {heap 896k} <free-fnsummary> {heap 896k} <single-use> {heap 896k} <comdats> {heap 896k}      .text
Assembling functions:
        .section        .rodata
        .align  3
        .type   _ZL5mul02, @object
        .size   _ZL5mul02, 4
_ZL5mul02:
        .byte   1
        .byte   1
        .byte   0
        .byte   1

/home/xenon/z.cc: At global scope:
/home/xenon/z.cc:13:34: internal compiler error: in output_constructor_regular_field, at varasm.c:5512
   13 | static constexpr Mul02Table mul02;
      |                                  ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

由于交叉编译没问题,stage1 也没问题(这个其实比较可疑,没想明白原因),问题肯定在 gcc/config/loongarch 某处,gcc 把自己编译错了,而和 C++ 语言前端无关。

附上 stacktrace(拿我系统编译器产生的):

/home/xenon/z.cc:13:34: internal compiler error: in output_constructor_regular_field, at varasm.c:5512
   13 | static constexpr Mul02Table mul02;
      |                                  ^
0xbd972b output_constructor_regular_field
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:5512
0xbd972b output_constructor
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:5824
0xbd8e43 output_constructor_regular_field
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:5557
0xbd8e43 output_constructor
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:5824
0xbdc2c3 assemble_variable_contents
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:2235
0xbe5cff assemble_variable_contents
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:2414
0xbe5cff assemble_variable(tree_node*, int, int, int)
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varasm.c:2414
0xbe94e3 varpool_node::assemble_decl()
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/varpool.c:596
0x4c21bb output_in_order
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cgraphunit.c:2141
0x4c21bb symbol_table::compile()
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cgraphunit.c:2345
0x4c4d53 symbol_table::compile()
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cgraphunit.c:2261
0x4c4d53 symbol_table::finalize_compilation_unit()
        /tmp/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cgraphunit.c:2529
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.

@redeastcn
Copy link
Author

loongson/build-tools#12 (comment)
Makiras提到:
感觉可能和这个问题有关
gcc-mirror/gcc@4d7dfad
目前loongarch没有处理这个问题相关的代码

@xen0n
Copy link

xen0n commented Jan 27, 2022

loongson/build-tools#12 (comment) Makiras提到: 感觉可能和这个问题有关 gcc-mirror/gcc@4d7dfad 目前loongarch没有处理这个问题相关的代码

确认了这个 fix 解决不了这边的问题,stage2 仍然 ICE

@Makiras
Copy link

Makiras commented Jan 27, 2022

之前还找到的另外一个可能是riscv_flatten_aggregate_field的修改,但看了你的最小复现之后觉得可能性不大了
gcc-mirror@e98c3ee

@xen0n
Copy link

xen0n commented Feb 9, 2022

之前还找到的另外一个可能是riscv_flatten_aggregate_field的修改,但看了你的最小复现之后觉得可能性不大了 gcc-mirror@e98c3ee

这个昨天确认了,也解决不了问题

@xen0n
Copy link

xen0n commented Feb 9, 2022

cross post from loongson/build-tools#12:

昨晚发现stage1工作的原因是没开优化,也就是确定问题出在LoongArch machine description个别只有开优化才生效的pattern上

@xen0n
Copy link

xen0n commented Feb 10, 2022

确认这个问题被 upstream v6.2 分支修复了(我使用的集成分支 https://github.com/xen0n/gcc/commits/for-gentoo-gcc-12-v20220210

For the record: (likely fixed by the added bstrpick/alsl constraints)

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index fa7e24c31df..2cd3ff76dfb 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -1286,7 +1286,7 @@
 	     (match_operand:SHORT 1 "nonimmediate_operand" "r,m")))]
   ""
   "@
-   bstrpick.<d>\t%0,%1,<SHORT:qi_hi>,0
+   bstrpick.w\t%0,%1,<SHORT:qi_hi>,0
    ld.<SHORT:size>u\t%0,%1"
   [(set_attr "move_type" "pick_ins,load")
    (set_attr "compression" "*,*")
@@ -1309,7 +1309,7 @@
 	(zero_extend:GPR
 	    (truncate:SHORT (match_operand:DI 1 "register_operand" "r"))))]
   "TARGET_64BIT"
-  "bstrpick.<d>\t%0,%1,<SHORT:qi_hi>,0"
+  "bstrpick.w\t%0,%1,<SHORT:qi_hi>,0"
   [(set_attr "move_type" "pick_ins")
    (set_attr "mode" "<GPR:MODE>")])
 
@@ -1404,7 +1404,7 @@
 	(sign_extend:HI
 	    (truncate:QI (match_operand:DI 1 "register_operand" "r"))))]
   "TARGET_64BIT"
-  "ext.w.<size>\t%0,%1"
+  "ext.w.b\t%0,%1"
   [(set_attr "move_type" "signext")
    (set_attr "mode" "SI")])
 
@@ -2500,12 +2500,24 @@
   [(set_attr "type" "shift,shift")
    (set_attr "mode" "<MODE>")])
 
+;; The following templates were added to generate "bstrpick.d + alsl.d"
+;; instruction pairs.
+;; It is required that the values of const_immlsa_operand and
+;; shift_mask_operand must have the following correspondence:
+;;
+;; const_immlsa_operand       shift_mask_operand
+;;         1            <=>       0x1fffffffe
+;;         2            <=>       0x3fffffffc
+;;         3            <=>       0x7fffffff8
+;;         4            <=>       0xffffffff0
+
 (define_insn "zero_extend_ashift1"
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(and:DI (ashift:DI (subreg:DI (match_operand:SI 1 "register_operand" "r") 0)
 			   (match_operand 2 "const_immlsa_operand" ""))
 		(match_operand 3 "shift_mask_operand" "")))]
-  "TARGET_64BIT"
+  "TARGET_64BIT
+   && (((((1 << INTVAL (operands[2])) - 1) + (INTVAL (operands[3]))) & 0xf) == 0xf)"
   "bstrpick.d\t%0,%1,31,0\n\talsl.d\t%0,%0,$r0,%2"
   [(set_attr "type" "arith")
    (set_attr "mode" "DI")
@@ -2516,7 +2528,8 @@
 	(and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r")
 			   (match_operand 2 "const_immlsa_operand" ""))
 		(match_operand 3 "shift_mask_operand" "")))]
-  "TARGET_64BIT"
+  "TARGET_64BIT
+   && (((((1 << INTVAL (operands[2])) - 1) + (INTVAL (operands[3]))) & 0xf) == 0xf)"
   "bstrpick.d\t%0,%1,31,0\n\talsl.d\t%0,%0,$r0,%2"
   [(set_attr "type" "arith")
    (set_attr "mode" "DI")
@@ -2525,10 +2538,11 @@
 (define_insn "alsl_paired1"
   [(set (match_operand:DI 0 "register_operand" "=&r")
 	(plus:DI (and:DI (ashift:DI (subreg:DI (match_operand:SI 1 "register_operand" "r") 0)
-			   (match_operand 2 "const_immlsa_operand" ""))
-			(match_operand 3 "shift_mask_operand" ""))
-		(match_operand:DI 4 "register_operand" "r")))]
-  "TARGET_64BIT"
+				    (match_operand 2 "const_immlsa_operand" ""))
+			 (match_operand 3 "shift_mask_operand" ""))
+		 (match_operand:DI 4 "register_operand" "r")))]
+  "TARGET_64BIT
+   && (((((1 << INTVAL (operands[2])) - 1) + (INTVAL (operands[3]))) & 0xf) == 0xf)"
   "bstrpick.d\t%0,%1,31,0\n\talsl.d\t%0,%0,%4,%2"
   [(set_attr "type" "arith")
   (set_attr "mode" "DI")
@@ -2537,10 +2551,11 @@
 (define_insn "alsl_paired2"
   [(set (match_operand:DI 0 "register_operand" "=&r")
 	(plus:DI (match_operand:DI 1 "register_operand" "r")
-		(and:DI (ashift:DI (match_operand:DI 2 "register_operand" "r")
-			   (match_operand 3 "const_immlsa_operand" ""))
-			(match_operand 4 "shift_mask_operand" ""))))]
-  "TARGET_64BIT"
+		 (and:DI (ashift:DI (match_operand:DI 2 "register_operand" "r")
+				    (match_operand 3 "const_immlsa_operand" ""))
+			 (match_operand 4 "shift_mask_operand" ""))))]
+  "TARGET_64BIT
+   && (((((1 << INTVAL (operands[3])) - 1) + (INTVAL (operands[4]))) & 0xf) == 0xf)"
   "bstrpick.d\t%0,%2,31,0\n\talsl.d\t%0,%0,%1,%3"
   [(set_attr "type" "arith")
    (set_attr "mode" "DI")
@@ -2549,8 +2564,8 @@
 (define_insn "alsl<mode>3"
   [(set (match_operand:GPR 0 "register_operand" "=r")
 	(plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "r")
-			     (match_operand 2 "const_immlsa_operand" ""))
-		(match_operand:GPR 3 "register_operand" "r")))]
+			      (match_operand 2 "const_immlsa_operand" ""))
+		  (match_operand:GPR 3 "register_operand" "r")))]
   ""
   "alsl.<d>\t%0,%1,%3,%2"
   [(set_attr "type" "arith")
diff --git a/gcc/config/loongarch/predicates.md b/gcc/config/loongarch/predicates.md
index 1a8ab26d21e..be07887915d 100644
--- a/gcc/config/loongarch/predicates.md
+++ b/gcc/config/loongarch/predicates.md
@@ -252,25 +252,10 @@
   (and (match_code "const_int")
        (match_test "UINTVAL (op) == 0xffffffff")))
 
-(define_predicate "and_load_operand"
-  (ior (match_operand 0 "qi_mask_operand")
-       (match_operand 0 "hi_mask_operand")
-       (match_operand 0 "si_mask_operand")))
-
 (define_predicate "low_bitmask_operand"
   (and (match_code "const_int")
        (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")))
 
-(define_predicate "and_reg_operand"
-  (ior (match_operand 0 "register_operand")
-       (match_operand 0 "const_uns_arith_operand")
-       (match_operand 0 "low_bitmask_operand")
-       (match_operand 0 "si_mask_operand")))
-
-(define_predicate "and_operand"
-  (ior (match_operand 0 "and_load_operand")
-       (match_operand 0 "and_reg_operand")))
-
 (define_predicate "d_operand"
   (and (match_code "reg")
        (match_test "GP_REG_P (REGNO (op))")))

@redeastcn
Copy link
Author

大家辛苦了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants