Bug 91090 - A suspicious code in tree-ssa-dom.c
Summary: A suspicious code in tree-ssa-dom.c
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Jeffrey A. Law
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-05 04:58 UTC by Feng Xue
Modified: 2019-07-07 18:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-07-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Feng Xue 2019-07-05 04:58:59 UTC
Find code snippet in simplify_stmt_for_jump_threading ():

      if (vr->kind () == VR_RANGE)
	{
	  size_t i, j;

	  find_case_label_range (switch_stmt, vr->min (), vr->max (), &i, &j);

	  if (i == j)
	    {
	      tree label = gimple_switch_label (switch_stmt, i);
	      tree singleton;

	      if (CASE_HIGH (label) != NULL_TREE
		  ? (tree_int_cst_compare (CASE_LOW (label), vr->min ()) <= 0
		     && tree_int_cst_compare (CASE_HIGH (label), vr->max ()) >= 0)
		  : (vr->singleton_p (&singleton)
		     && tree_int_cst_equal (CASE_LOW (label), singleton)))
		return label;

	      if (i > j)
		return gimple_switch_label (switch_stmt, 0);
	    }
	}

The conditional "if (i > j)" should be outside of "if (i == j)"?
Comment 1 Richard Biener 2019-07-05 08:51:00 UTC
Jeff - you touched this code last.
Comment 2 Jeffrey A. Law 2019-07-06 16:25:55 UTC
I think that if (i > j) case should be at the same level as the (i == j) case.  It probably got goof'd up during reindention when the code was copied from tree-vrp.c.
Comment 3 Jeffrey A. Law 2019-07-07 18:43:16 UTC
Author: law
Date: Sun Jul  7 18:42:45 2019
New Revision: 273184

URL: https://gcc.gnu.org/viewcvs?rev=273184&root=gcc&view=rev
Log:
        PR tree-optimization/91090
        * tree-ssa-dom.c (simplify_stmt_for_jump_threading): Fix logic error
        in handling of ranges to simplify switch statements.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-ssa-dom.c
Comment 4 Jeffrey A. Law 2019-07-07 18:46:40 UTC
Fixed on the trunk.  Only causes missed optimizations, so I don't think there's a strong need to backport to the release branches.