[Bug tree-optimization/71691] [6/7 Regression] wrong code at -O3 in both 32-bit and 64-bit modes on x86_64-linux-gnu (Floating point exception)

law at redhat dot com gcc-bugzilla@gcc.gnu.org
Tue Aug 9 17:29:00 GMT 2016


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

--- Comment #9 from Jeffrey A. Law <law at redhat dot com> ---
Based on c#6 I started thinking about how to make tree-ssa-loop-unswitch.c
appropriately conservative when a condition references a maybe-undefined
SSA_NAME.

To recap, tree_may_unswitch_on has this test:

     /* Unswitching on undefined values would introduce undefined
         behavior that the original program might never exercise.  */
      if (ssa_undefined_value_p (use, true))
        return NULL_TREE;

The problem is ssa_undefined_value_p returns an optimistic result -- ie, it
will returns true iff the definition statement is empty.  So it will return
false for an SSA_NAME that is set from a PHI node where one or more arguments
have undefined values.

ISTM this can be pretty easily fixed.

Create a bitmap and initialize it to all the SSA_NAMEs where
ssa_undefined_value_p is true.

Examine each PHI, if the PHI has an argument on its RHS that has the bit set in
the bitmap, then set the bit for the LHS of the PHI

Iterate on the PHIs until nothing has changed.

[ Yes, this isn't the most efficient.  Implementation would be different to
improve efficiency. ]

The result is the conservative set of SSA_NAMEs that may be undefined.  This
satisfies the need of unswitching and potentially other passes that really want
the conservative set.  


Thoughts?


More information about the Gcc-bugs mailing list