Created attachment 46499 [details] test-case Attached test-case (reduced from 521.wrf_r) fails: $ gcc fice.f90 -c -march=native -Ofast fice.f90:10:30: 10 | OVERALL_MAIN_I_LOOP: do i=its, OLD_CLOUD_NSUBMIX_LOOP | 1 Warning: Deleted feature: End expression in DO loop at (1) must be integer during RTL pass: expand fice.f90:18:0: 18 | ccnfact(l,m,n)=cm3 | internal compiler error: in maybe_gen_insn, at optabs.c:7341 0x68f8c8 maybe_gen_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7341 0xcf4888 maybe_expand_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7385 0xcf4888 expand_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7416 0xbd1c8b expand_mask_store_optab_fn /home/marxin/Programming/gcc/gcc/internal-fn.c:2535 0x9a6b47 expand_call_stmt /home/marxin/Programming/gcc/gcc/cfgexpand.c:2638 0x9a6b47 expand_gimple_stmt_1 /home/marxin/Programming/gcc/gcc/cfgexpand.c:3709 0x9a6b47 expand_gimple_stmt /home/marxin/Programming/gcc/gcc/cfgexpand.c:3868 0x9ac351 expand_gimple_basic_block /home/marxin/Programming/gcc/gcc/cfgexpand.c:5904 0x9ae0b7 execute /home/marxin/Programming/gcc/gcc/cfgexpand.c:6527
$ (gdb) bt #0 fancy_abort (file=0x18cc0d0 "/home/marxin/Programming/gcc/gcc/optabs.c", line=7341, function=0x18cc738 "maybe_gen_insn") at /home/marxin/Programming/gcc/gcc/diagnostic.c:1614 #1 0x0000000000d16618 in maybe_gen_insn (icode=CODE_FOR_nothing, nops=3, ops=0x7fffffffd580) at /home/marxin/Programming/gcc/gcc/optabs.c:7341 #2 0x0000000000d16a68 in maybe_expand_insn (icode=CODE_FOR_nothing, nops=3, ops=0x7fffffffd580) at /home/marxin/Programming/gcc/gcc/optabs.c:7385 #3 0x0000000000d16afc in expand_insn (icode=CODE_FOR_nothing, nops=3, ops=0x7fffffffd580) at /home/marxin/Programming/gcc/gcc/optabs.c:7416 #4 0x0000000000be03e4 in expand_mask_store_optab_fn (stmt=0x7ffff756d7e0, optab=maskstore_optab) at /home/marxin/Programming/gcc/gcc/internal-fn.c:2536 #5 0x0000000000be3f18 in expand_MASK_STORE (fn=IFN_MASK_STORE, stmt=0x7ffff756d7e0) at /home/marxin/Programming/gcc/gcc/internal-fn.def:133 #6 0x0000000000be5406 in expand_internal_call (fn=IFN_MASK_STORE, stmt=0x7ffff756d7e0) at /home/marxin/Programming/gcc/gcc/internal-fn.c:3573 #7 0x0000000000be5431 in expand_internal_call (stmt=0x7ffff756d7e0) at /home/marxin/Programming/gcc/gcc/internal-fn.c:3581 #8 0x00000000009af7f8 in expand_call_stmt (stmt=0x7ffff756d7e0) at /home/marxin/Programming/gcc/gcc/cfgexpand.c:2638 #9 expand_gimple_stmt_1 (stmt=<gimple_call 0x7ffff756d7e0>) at /home/marxin/Programming/gcc/gcc/cfgexpand.c:3709 #10 expand_gimple_stmt (stmt=<gimple_call 0x7ffff756d7e0>) at /home/marxin/Programming/gcc/gcc/cfgexpand.c:3868 #11 0x00000000009b5002 in expand_gimple_basic_block (bb=<optimized out>, disable_tail_calls=<optimized out>) at /home/marxin/Programming/gcc/gcc/cfgexpand.c:5908 #12 0x00000000009b6d68 in (anonymous namespace)::pass_expand::execute (this=<optimized out>, fun=0x7ffff7903000) at /home/marxin/Programming/gcc/gcc/cfgexpand.c:6531 #13 0x0000000000d35cfa in execute_one_pass (pass=<opt_pass* 0x23cce30 "expand"(238)>) at /home/marxin/Programming/gcc/gcc/passes.c:2473 #14 0x0000000000d36450 in execute_pass_list_1 (pass=<opt_pass* 0x23cce30 "expand"(238)>) at /home/marxin/Programming/gcc/gcc/passes.c:2559 #15 0x0000000000d36489 in execute_pass_list (fn=0x7ffff7903000, pass=<optimized out>) at /home/marxin/Programming/gcc/gcc/passes.c:2570 #16 0x00000000009ec780 in cgraph_node::expand (this=<cgraph_node * const 0x7ffff77312d0 "prescribe_aerosol_mixactivate"/0>) at /home/marxin/Programming/gcc/gcc/context.h:48 #17 0x00000000009ed71c in expand_all_functions () at /home/marxin/Programming/gcc/gcc/cgraphunit.c:2332 #18 symbol_table::compile (this=0x7ffff7732100) at /home/marxin/Programming/gcc/gcc/cgraphunit.c:2683 #19 0x00000000009eff1d in symbol_table::compile (this=0x7ffff7732100) at /home/marxin/Programming/gcc/gcc/cgraphunit.c:2861 #20 symbol_table::finalize_compilation_unit (this=0x7ffff7732100) at /home/marxin/Programming/gcc/gcc/cgraphunit.c:2861 #21 0x0000000000e09e3d in compile_file () at /home/marxin/Programming/gcc/gcc/toplev.c:481 #22 0x00000000007f1938 in do_compile () at /home/marxin/Programming/gcc/gcc/toplev.c:2209 #23 toplev::main (this=this@entry=0x7fffffffdabe, argc=<optimized out>, argc@entry=14, argv=<optimized out>, argv@entry=0x7fffffffdbb8) at /home/marxin/Programming/gcc/gcc/toplev.c:2344 #24 0x00000000007f544f in main (argc=14, argv=0x7fffffffdbb8) at /home/marxin/Programming/gcc/gcc/main.c:39 $ (gdb) frame 4 #4 0x0000000000be03e4 in expand_mask_store_optab_fn (stmt=0x7ffff756d7e0, optab=maskstore_optab) at /home/marxin/Programming/gcc/gcc/internal-fn.c:2536 2536 expand_insn (icode, 3, ops); (gdb) p stmt $3 = (gcall *) 0x7ffff756d7e0 (gdb) pgg warning: Expression is not an assignment (and might have no effect) # .MEM_188 = VDEF <_173> .MASK_STORE (_485, 32B, _157, cm3_125(D)); $ (gdb) p mem $4 = (rtx) 0x7ffff76e38e8 (gdb) pr warning: Expression is not an assignment (and might have no effect) (mem:SF (reg/f:DI 316 [ _484 ]) [1 MEM[base: _484, offset: 0B]+0 S4 A32]) (gdb) p mask $5 = (rtx) 0x7ffff76e3af8 (gdb) pr warning: Expression is not an assignment (and might have no effect) (subreg:QI (reg:HI 489) 0) (gdb) p reg $6 = (rtx) 0x7ffff76c9c18 (gdb) pr warning: Expression is not an assignment (and might have no effect) (reg/v:SF 151 [ cm3 ]) (gdb) p type $7 = <real_type 0x7ffff774b2a0 real(kind=4)> (gdb) p maskt $8 = <ssa_name 0x7ffff7927798>
Created attachment 46500 [details] optimized dump file
Reproduced with -Ofast -march=znver1 -mveclibabi=svml
Somehow we end up with (gdb) p debug_tree (maskt) <ssa_name 0x7ffff6e35798 type <boolean_type 0x7ffff6c52b28 logical(kind=1) public unsigned QI size <integer_cst 0x7ffff6c3dc60 constant 8> unit-size <integer_cst 0x7ffff6c3dc78 constant 1> align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff6c52b28 precision:1 min <integer_cst 0x7ffff6c3deb8 0> max <integer_cst 0x7ffff6c3dee8 1>> visited def_stmt _157 = _155 & _21; version:157> this must be a latent issue.
Somewhat reduced: ! PR tree-optimization/90913 ! { dg-do compile } ! { dg-options "-O3 -ffast-math" } ! { dg-additional-options "-mavx -mveclibabi=svml" { target i?86-*-* x86_64-*-* } } subroutine foo (a, b, c, d, e, f, g, h, k, l) implicit none integer :: d, e, f, g, i, j real :: a, b(5,6), c(6), h(6,10,5), k(5,10,2), l(10,5), m, n, o do i=1,5 do j=1,6 m=l(f,g)*log(c(j)) if (m<2) then if (m<-2) then h(j,f,g)=n else h(j,f,g)=o endif endif b(i,j)=a+k(i,d,e)+k(i,1,e)**h(j,f,g) enddo enddo write(*,'()') end
The ICE is because .MASK_LOAD/.MASK_STORE calls are supported just for vectors. The way it is done is that during ifcvt those internal calls are added to the .LOOP_VECTORIZED guarded loops, and either we successfully vectorize those, then the .MASK_LOAD/.MASK_STORE ifn calls are replaced with their vectorized versions and all the checking is performed, or we should DCE that loop. The r272239 change which I haven't really understood breaks this on this testcase, we end up with _116 = .LOOP_VECTORIZED (1, 4); if (_116 != 0) goto <bb 25>; [100.00%] else goto <bb 26>; [100.00%] that guards these scalar .MASK_STORE calls being replaced with _116 = 0; if (_190 != 0) goto <bb 25>; [100.00%] else goto <bb 26>; [100.00%] that is just wrong, we can't and shouldn't reuse the for vectorization only loop if we don't vectorize it. Both because of these .MASK* calls, but also because e.g. there are COND_EXPRs all around in that which often isn't beneficial in scalar loops, etc.
Aww. OK, so this is when we vectorize the inner loop of an if-converted outer-loop, then the outer loop LOOP_VECTORIZED condition replaced with the versioning condition dispatches to the variant supposed to be _scalar_ and the fallback is the if-converted nested copy designed for vectorization. So re-using the if-conversion copy is only possible when loop_to_version is the inner loop or we are vectorizing the outer loop (I think we never do versioning on outer loops currently though). Testing patch.
One more test-case: $ gcc /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr70177.c -fwrapv -mavx5124fmaps -O3 during RTL pass: expand /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr70177.c: In function ‘foo’: /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr70177.c:8:1: internal compiler error: in maybe_gen_insn, at optabs.c:7379 8 | foo (int i, int j) | ^~~ 0x693c2c maybe_gen_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7379 0xc80838 maybe_expand_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7423 0xc80838 expand_insn(insn_code, unsigned int, expand_operand*) /home/marxin/Programming/gcc/gcc/optabs.c:7454 0xb5d98b expand_mask_store_optab_fn /home/marxin/Programming/gcc/gcc/internal-fn.c:2536 0x9345e7 expand_call_stmt /home/marxin/Programming/gcc/gcc/cfgexpand.c:2638 0x9345e7 expand_gimple_stmt_1 /home/marxin/Programming/gcc/gcc/cfgexpand.c:3709 0x9345e7 expand_gimple_stmt /home/marxin/Programming/gcc/gcc/cfgexpand.c:3868 0x939df1 expand_gimple_basic_block /home/marxin/Programming/gcc/gcc/cfgexpand.c:5908 0x93bb57 execute /home/marxin/Programming/gcc/gcc/cfgexpand.c:6531
Author: rguenth Date: Fri Jun 21 11:10:39 2019 New Revision: 272545 URL: https://gcc.gnu.org/viewcvs?rev=272545&root=gcc&view=rev Log: 2019-06-21 Richard Biener <rguenther@suse.de> PR tree-optimization/90913 * tree-vect-loop-manip.c (vect_loop_versioning): Do not re-use the scalar variant of if-conversion versioning. * gfortran.dg/vect/pr90913.f90: New testcase. Added: trunk/gcc/testsuite/gfortran.dg/vect/pr90913.f90 Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-vect-loop-manip.c
Should be fixed now.