Bug 112496 - [13/14 Regression] ICE: in vectorizable_nonlinear_induction, at tree-vect-loop.cc with bit fields
Summary: [13/14 Regression] ICE: in vectorizable_nonlinear_induction, at tree-vect-loo...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P2 normal
Target Milestone: 13.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, needs-bisection
Depends on:
Blocks:
 
Reported: 2023-11-12 14:50 UTC by wierton
Modified: 2023-11-15 06:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 12.3.0
Known to fail: 13.1.0, 13.2.0
Last reconfirmed: 2023-11-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wierton 2023-11-12 14:50:11 UTC
Compiler Explorer: https://gcc.godbolt.org/z/7aq3hjbjK

When compile this program with `gcc-14 -O2`, gcc ICEs:
```
struct T { int x : 24; } v;
void f1(int x) {
  while (v.x - ((v.x <<= 1) - v.x)) ;
}
```

The crash output:
```
during GIMPLE pass: vect
<source>: In function 'f1':
<source>:2:6: internal compiler error: in vectorizable_nonlinear_induction, at tree-vect-loop.cc:9573
    2 | void f1(int x) {
      |      ^~
0x238b15e internal_error(char const*, ...)
	???:0
0xa11270 fancy_abort(char const*, int, char const*)
	???:0
0x13ec547 vectorizable_induction(_loop_vec_info*, _stmt_vec_info*, gimple**, _slp_tree*, vec<stmt_info_for_cost, va_heap, vl_ptr>*)
	???:0
0x13fe290 vect_analyze_loop(loop*, vec_info_shared*)
	???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```
Comment 1 Andrew Pinski 2023-11-12 16:15:11 UTC
Confirmed.
Comment 2 Richard Biener 2023-11-13 09:27:59 UTC
 if (TREE_CODE (init_expr) == INTEGER_CST)
    init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
  else
    gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
                                       TREE_TYPE (init_expr)));

and init_expr is a 24 bit integer type while vectype has 32bit components.

The "fix" is to bail out instead of asserting.
Comment 3 Hongtao.liu 2023-11-13 09:31:47 UTC
(In reply to Richard Biener from comment #2)
>  if (TREE_CODE (init_expr) == INTEGER_CST)
>     init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
>   else
>     gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
>                                        TREE_TYPE (init_expr)));
> 
> and init_expr is a 24 bit integer type while vectype has 32bit components.
> 
> The "fix" is to bail out instead of asserting.

Agree.
Comment 4 GCC Commits 2023-11-14 08:41:21 UTC
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:f28306b4fd309b579c8a4a5bf2f1b24fa40f8f7f

commit r14-5433-gf28306b4fd309b579c8a4a5bf2f1b24fa40f8f7f
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Nov 13 17:56:49 2023 +0800

    Fix ICE in vectorizable_nonlinear_induction with bitfield.
    
     if (TREE_CODE (init_expr) == INTEGER_CST)
        init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
      else
        gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
                                           TREE_TYPE (init_expr)));
    
    and init_expr is a 24 bit integer type while vectype has 32bit components.
    
    The "fix" is to bail out instead of asserting.
    
    gcc/ChangeLog:
    
            PR tree-optimization/112496
            * tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
            false when !tree_nop_conversion_p (TREE_TYPE (vectype),
            TREE_TYPE (init_expr)).
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr112496.c: New test.
Comment 5 GCC Commits 2023-11-14 23:53:16 UTC
The releases/gcc-13 branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:ed73ad337739a4244e8040d19b6e567c4101b58a

commit r13-8068-ged73ad337739a4244e8040d19b6e567c4101b58a
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Nov 13 17:56:49 2023 +0800

    Fix ICE in vectorizable_nonlinear_induction with bitfield.
    
     if (TREE_CODE (init_expr) == INTEGER_CST)
        init_expr = fold_convert (TREE_TYPE (vectype), init_expr);
      else
        gcc_assert (tree_nop_conversion_p (TREE_TYPE (vectype),
                                           TREE_TYPE (init_expr)));
    
    and init_expr is a 24 bit integer type while vectype has 32bit components.
    
    The "fix" is to bail out instead of asserting.
    
    gcc/ChangeLog:
    
            PR tree-optimization/112496
            * tree-vect-loop.cc (vectorizable_nonlinear_induction): Return
            false when !tree_nop_conversion_p (TREE_TYPE (vectype),
            TREE_TYPE (init_expr)).
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr112496.c: New test.
    
    (cherry picked from commit f28306b4fd309b579c8a4a5bf2f1b24fa40f8f7f)
Comment 6 Sam James 2023-11-15 06:36:51 UTC
Fixed for 13.3 then.