--- /dev/null
+package body Opt77_Pkg is
+
+ function Compare (S : String) return Boolean is
+ begin
+ return S = "Two";
+ end;
+
+ procedure Proc (S : String; N : in out Natural; To_Add : out Boolean) is
+ To_Take : Boolean := False;
+ To_Read : Boolean := False;
+ begin
+ To_Add := False;
+
+ if S = "One" then
+ To_Read := True;
+ To_Take := Compare (S);
+ end if;
+
+ if To_Read and not To_Take then
+ N := N + 1;
+ end if;
+
+ if To_Take then
+ To_Add := True;
+ end if;
+ end;
+
+end Opt77_Pkg;
gimple *def_stmt = SSA_NAME_DEF_STMT (name);
if (is_gimple_assign (def_stmt))
{
- /* We know the result of DEF_STMT was zero. See if that allows
- us to deduce anything about the SSA_NAMEs used on the RHS. */
enum tree_code code = gimple_assign_rhs_code (def_stmt);
switch (code)
{
+ /* If the result of an OR is zero, then its operands are, too. */
case BIT_IOR_EXPR:
if (integer_zerop (value))
{
}
break;
- /* We know the result of DEF_STMT was one. See if that allows
- us to deduce anything about the SSA_NAMEs used on the RHS. */
+ /* If the result of an AND is nonzero, then its operands are, too. */
case BIT_AND_EXPR:
if (!integer_zerop (value))
{
break;
}
-
case EQ_EXPR:
case NE_EXPR:
{
case NEGATE_EXPR:
{
tree rhs = gimple_assign_rhs1 (def_stmt);
- tree res = fold_build1 (code, TREE_TYPE (rhs), value);
+ tree res;
+ /* If this is a NOT and the operand has a boolean range, then we
+ know its value must be zero or one. We are not supposed to
+ have a BIT_NOT_EXPR for boolean types with precision > 1 in
+ the general case, see e.g. the handling of TRUTH_NOT_EXPR in
+ the gimplifier, but it can be generated by match.pd out of
+ a BIT_XOR_EXPR wrapped in a BIT_AND_EXPR. Now the handling
+ of BIT_AND_EXPR above already forces a specific semantics for
+ boolean types with precision > 1 so we must do the same here,
+ otherwise we could change the semantics of TRUTH_NOT_EXPR for
+ boolean types with precision > 1. */
+ if (code == BIT_NOT_EXPR
+ && TREE_CODE (rhs) == SSA_NAME
+ && ssa_name_has_boolean_range (rhs))
+ {
+ if (integer_zerop (value))
+ res = build_one_cst (TREE_TYPE (rhs));
+ else
+ res = build_zero_cst (TREE_TYPE (rhs));
+ }
+ else
+ res = fold_build1 (code, TREE_TYPE (rhs), value);
derive_equivalences (rhs, res, recursion_limit - 1);
break;
}