https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103192

--- Comment #10 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
The guard seems to be removed by the vrp2 pass, not by jump threading.

a.ii.195t.vrp2:Folding predicate iftmp.2373_1515 != 0B to 1

For some bizarre reason, ranger thinks iftmp.2373_1515 is nonzero and removes
the check against zero:

=========== BB 219 ============
region_type_1384(D)     unsigned int VARYING
ctx_1386        struct gimplify_omp_ctx * [1B, +INF]
code_1387(D)    tree_code [0, 65535]
outer_ctx_1389  struct gimplify_omp_ctx * VARYING
_2620   bool VARYING
c_3771  union tree_node * [1B, +INF]
_3783   bool VARYING
    <bb 219> [local count: 105119385]:
    iftmp.2340_1256 = code_1387(D) == 199 ? 81 : 80;
    iftmp.2304_1247 = code_1387(D) == 195 ? 81 : 80;
    check_non_private_1152 = code_1387(D) != 177 ? "lastprivate" : 0B;
    iftmp.2373_1515 = code_1387(D) != 181 ? ctx_1386 : outer_ctx_1389;

iftmp.2304_1247 : gomp_map_kind [80, 81]
iftmp.2340_1256 : gomp_map_kind [80, 81]
iftmp.2373_1515 : struct gimplify_omp_ctx * [1B, +INF]

Notice the non-zero range on exit.

To reproduce:

tmcc1plus a.ii -O2 -fdisable-tree-threadfull2 -fdisable-tree-threadfull1
-fdisable-tree-thread2 -fdisable-tree-thread1
-fdbg-cnt=registered_jump_thread:543-543:544-544:550-550:551-551:552-552:553-553:554-554:555-555
-fno-PIE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -fno-common
-fdump-tree-all-lineno 

and search for:

:10070:.*omp_add_variable

...in the vrp2 dump.  There's no guard on iftmp.2373_1515 because the check was
removed.

It is possible that threadfull2, which uses the ranger engine and runs before
vrp2, was threading the check, since ranger obviously thinks it's a constant. 
This is why removing threadfull2 didn't fix the problem, since vrp2 (which is
now using ranger) will make the same conclusion, albeit with a different
approach (remove the conditional instead of thread the path).

And indeed, if I add --param=vrp2-mode=vrp, to the above steps, the problem
goes away.

So, this is ranger...not the threader.  I'm going to put this aside while I
take a look at the other P1s that are completely the threader's fault, and if
Andrew doesn't get to it before, I'll come back to this.

Reply via email to