GCC Middle and Back End API Reference
gimple-fold.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "flags.h"
#include "function.h"
#include "dumpfile.h"
#include "bitmap.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-ssanames.h"
#include "tree-into-ssa.h"
#include "tree-dfa.h"
#include "tree-ssa.h"
#include "tree-ssa-propagate.h"
#include "target.h"
#include "ipa-utils.h"
#include "gimple-pretty-print.h"
#include "tree-ssa-address.h"
Include dependency graph for gimple-fold.c:

Functions

static bool can_refer_decl_in_current_unit_p ()
tree canonicalize_constructor_val ()
tree get_symbol_constant_value ()
static tree maybe_fold_reference ()
static tree fold_gimple_assign ()
static bool fold_gimple_cond ()
void gimplify_and_update_call_from_tree ()
static bool get_maxval_strlen ()
tree gimple_fold_builtin ()
tree gimple_extract_devirt_binfo_from_cst ()
static bool gimple_fold_call ()
static bool fold_stmt_1 ()
bool fold_stmt ()
bool fold_stmt_inplace ()
static tree canonicalize_bool ()
static bool same_bool_comparison_p (const_tree expr, enum tree_code code, const_tree op1, const_tree op2)
static bool same_bool_result_p ()
static tree and_comparisons_1 (enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b)
static tree and_var_with_comparison (tree var, bool invert, enum tree_code code2, tree op2a, tree op2b)
static tree and_var_with_comparison_1 (gimple stmt, enum tree_code code2, tree op2a, tree op2b)
static tree or_comparisons_1 (enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b)
static tree or_var_with_comparison (tree var, bool invert, enum tree_code code2, tree op2a, tree op2b)
static tree or_var_with_comparison_1 (gimple stmt, enum tree_code code2, tree op2a, tree op2b)
tree maybe_fold_and_comparisons (enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b)
tree maybe_fold_or_comparisons (enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b)
tree gimple_fold_stmt_to_constant_1 (gimple stmt, tree(*valueize)(tree))
tree gimple_fold_stmt_to_constant (gimple stmt, tree(*valueize)(tree))
static tree fold_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size, tree)
static tree get_base_constructor (tree base, HOST_WIDE_INT *bit_offset, tree(*valueize)(tree))
static tree fold_string_cst_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size)
static tree fold_array_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size, tree from_decl)
static tree fold_nonarray_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset, unsigned HOST_WIDE_INT size, tree from_decl)
tree fold_const_aggregate_ref_1 (tree t, tree(*valueize)(tree))
tree fold_const_aggregate_ref ()
tree gimple_get_virt_method_for_binfo ()
bool gimple_val_nonnegative_real_p ()
tree gimple_fold_indirect_ref ()

Function Documentation

static tree and_comparisons_1 ( enum tree_code  code1,
tree  op1a,
tree  op1b,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Forward declarations for some mutually recursive functions.

Try to simplify the AND of two comparisons defined by (OP1A CODE1 OP1B) and (OP2A CODE2 OP2B), respectively. If this can be done without constructing an intermediate value, return the resulting tree; otherwise NULL_TREE is returned. This function is deliberately asymmetric as it recurses on SSA_DEFs in the first comparison but not the second.

 First check for ((x CODE1 y) AND (x CODE2 y)).   
     Result will be either NULL_TREE, or a combined comparison.   
 Likewise the swapped case of the above.   
     Result will be either NULL_TREE, or a combined comparison.   
 If both comparisons are of the same value against constants, we might
 be able to merge them.   
     If we have (op1a == op1b), we should either be able to
     return that or FALSE, depending on whether the constant op1b
     also satisfies the other comparison against op2b.   
     Likewise if the second comparison is an == comparison.   
     Same business with inequality tests.   
     Chose the more restrictive of two < or <= comparisons.   
     Likewise chose the more restrictive of two > or >= comparisons.   
     Check for singleton ranges.   
     Check for disjoint ranges.  
 Perhaps the first comparison is (NAME != 0) or (NAME == 1) where
 NAME's definition is a truth value.  See if there are any simplifications
 that can be done against the NAME's definition.   
         Try to simplify by copy-propagating the definition.   
         If every argument to the PHI produces the same result when
         ANDed with the second comparison, we win.
         Do not do this unless the type is bool since we need a bool
         result here anyway.   
                 If this PHI has itself as an argument, ignore it.
                 If all the other args produce the same result,
                 we're still OK.   
                     In simple cases we can look through PHI nodes,
                     but we have to be careful with loops.
                     See PR49073.   

Referenced by same_bool_result_p().

static tree and_var_with_comparison ( tree  var,
bool  invert,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Helper function for and_comparisons_1: try to simplify the AND of the ssa variable VAR with the comparison specified by (OP2A CODE2 OP2B). If INVERT is true, invert the value of the VAR before doing the AND. Return NULL_EXPR if we can't simplify this to a single expression.

We can only deal with variables whose definitions are assignments.

 If we have an inverted comparison, apply DeMorgan's law and rewrite
 !var AND (op2a code2 op2b) => !(var OR !(op2a code2 op2b))
 Then we only have to consider the simpler non-inverted cases.   
static tree and_var_with_comparison_1 ( gimple  stmt,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Try to simplify the AND of the ssa variable defined by the assignment STMT with the comparison specified by (OP2A CODE2 OP2B). Return NULL_EXPR if we can't simplify this to a single expression.

 Check for identities like (var AND (var == 0)) => false.   
 If the definition is a comparison, recurse on it.   
 If the definition is an AND or OR expression, we may be able to
 simplify by reassociating.   
     Check for boolean identities that don't require recursive examination
     of inner1/inner2:
     inner1 AND (inner1 AND inner2) => inner1 AND inner2 => var
     inner1 AND (inner1 OR inner2) => inner1
     !inner1 AND (inner1 AND inner2) => false
     !inner1 AND (inner1 OR inner2) => !inner1 AND inner2
     Likewise for similar cases involving inner2.   
     Next, redistribute/reassociate the AND across the inner tests.
     Compute the first partial result, (inner1 AND (op2a code op2b))   
         Handle the AND case, where we are reassociating:
         (inner1 AND inner2) AND (op2a code2 op2b)
         => (t AND inner2)
         If the partial result t is a constant, we win.  Otherwise
         continue on to try reassociating with the other inner test.   
         Handle the OR case, where we are redistributing:
         (inner1 OR inner2) AND (op2a code2 op2b)
         => (t OR (inner2 AND (op2a code2 op2b)))   
         Save partial result for later.   
     Compute the second partial result, (inner2 AND (op2a code op2b))  
         Handle the AND case, where we are reassociating:
         (inner1 AND inner2) AND (op2a code2 op2b)
         => (inner1 AND t)   
             If both are the same, we can apply the identity
             (x AND x) == x.   
         Handle the OR case. where we are redistributing:
         (inner1 OR inner2) AND (op2a code2 op2b)
         => (t OR (inner1 AND (op2a code2 op2b)))
         => (t OR partial)   
                 We already got a simplification for the other
                 operand to the redistributed OR expression.  The
                 interesting case is when at least one is false.
                 Or, if both are the same, we can apply the identity
                 (x OR x) == x.   

References boolean_false_node, boolean_true_node, integer_onep(), and integer_zerop().

static bool can_refer_decl_in_current_unit_p ( )
static

Statement simplification on GIMPLE. Copyright (C) 2010-2013 Free Software Foundation, Inc. Split out from tree-ssa-ccp.c.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. Return true when DECL can be referenced from current unit. FROM_DECL (if non-null) specify constructor of variable DECL was taken from. We can get declarations that are not possible to reference for various reasons:

1) When analyzing C++ virtual tables. C++ virtual tables do have known constructors even when they are keyed to other compilation unit. Those tables can contain pointers to methods and vars in other units. Those methods have both STATIC and EXTERNAL set. 2) In WHOPR mode devirtualization might lead to reference to method that was partitioned elsehwere. In this case we have static VAR_DECL or FUNCTION_DECL that has no corresponding callgraph/varpool node declaring the body. 3) COMDAT functions referred by external vtables that we devirtualize only during final copmilation stage. At this time we already decided that we will not output the function body and thus we can't reference the symbol directly.

 We are concerned only about static/external vars and functions.   
 Static objects can be referred only if they was not optimized out yet.   
 We will later output the initializer, so we can refer to it.
 So we are concerned only when DECL comes from initializer of
 external var.   
 We are folding reference from external vtable.  The vtable may reffer
 to a symbol keyed to other compilation unit.  The other compilation
 unit may be in separate DSO and the symbol may be hidden.   
 When function is public, we always can introduce new reference.
 Exception are the COMDAT functions where introducing a direct
 reference imply need to include function body in the curren tunit.   
 We are not at ltrans stage; so don't worry about WHOPR.
 Also when still gimplifying all referred comdat functions will be
 produced.

 As observed in PR20991 for already optimized out comdat virtual functions
 it may be tempting to not necessarily give up because the copy will be
 output elsewhere when corresponding vtable is output.  
 This is however not possible - ABI specify that COMDATs are output in
 units where they are used and when the other unit was compiled with LTO
 it is possible that vtable was kept public while the function itself
 was privatized.  
 OK we are seeing either COMDAT or static variable.  In this case we must
 check that the definition is still around so we can refer it.   
     Check that we still have function body and that we didn't took
     the decision to eliminate offline copy of the function yet.
     The second is important when devirtualization happens during final
     compilation stage when making a new reference no longer makes callee
     to be compiled.   

References dyn_cast(), cgraph_node::global, cgraph_global_info::inlined_to, and symtab_get_node().

static tree canonicalize_bool ( )
static

Canonicalize and possibly invert the boolean EXPR; return NULL_TREE if EXPR is null or we don't know how. If non-null, the result always has boolean type.

tree canonicalize_constructor_val ( )

CVAL is value taken from DECL_INITIAL of variable. Try to transform it into acceptable form for is_gimple_min_invariant. FROM_DECL (if non-NULL) specify variable whose constructor contains CVAL.

Make sure we create a cgraph node for functions we'll reference.
They can be non-existent if the reference comes from an entry
of an external vtable for example.   

Fixup types in global initializers.

static tree fold_array_ctor_reference ( tree  type,
tree  ctor,
unsigned HOST_WIDE_INT  offset,
unsigned HOST_WIDE_INT  size,
tree  from_decl 
)
static

CTOR is CONSTRUCTOR of an array type. Fold reference of type TYPE and size SIZE to the memory at bit OFFSET.

 Compute low bound and elt size.   
     Static constructors for variably sized objects makes no sense.   
 Static constructors for variably sized objects makes no sense.   
 We can handle only constantly sized accesses that are known to not
 be larger than size of array element.   
 Compute the array index we look for.   
 And offset within the access.   
 See if the array field is large enough to span whole access.  We do not
 care to fold accesses spanning multiple array indexes.   
     Array constructor might explicitely set index, or specify range
     or leave index NULL meaning that it is next index after previous
     one.   
     Do we have match?   
 When memory is not explicitely mentioned in constructor,
 it is 0 (or out of range).   
tree fold_const_aggregate_ref ( )
tree fold_const_aggregate_ref_1 ( tree  t,
tree(*)(tree valueize 
)

Return the tree representing the element referenced by T if T is an ARRAY_REF or COMPONENT_REF into constant aggregates valuezing SSA names using VALUEIZE. Return NULL_TREE otherwise.

     Constant indexes are handled well by get_base_constructor.
     Only special case variable offsets.
     FIXME: This code can't handle nested references with variable indexes
     (they will be handled only by iteration of ccp).  Perhaps we can bring
     get_ref_base_and_extent here and make it use a valueize callback.   
         If the resulting bit-offset is constant, track it.   
             Empty constructor.  Always fold to 0.   
             Out of bound array access.  Value is undefined,
             but don't fold.   
             We can not determine ctor.   
     Fallthru.   
     Empty constructor.  Always fold to 0.   
     We do not know precise address.   
     We can not determine ctor.   
     Out of bound array access.  Value is undefined, but don't fold.   
static tree fold_ctor_reference ( tree  type,
tree  ctor,
unsigned HOST_WIDE_INT  offset,
unsigned HOST_WIDE_INT  size,
tree  from_decl 
)
static

The following set of functions are supposed to fold references using their constant initializers.

CTOR is value initializing memory, fold reference of type TYPE and size SIZE to the memory at bit OFFSET.

 We found the field with exact match.   
 We are at the end of walk, see if we can view convert the
 result.   
     VIEW_CONVERT_EXPR is defined only for matching sizes.   
static tree fold_gimple_assign ( )
static

Attempt to fold an assignment statement pointed-to by SI. Returns a replacement rhs for the statement or NULL_TREE if no simplification could be made. It is assumed that the operands have been previously folded.

Fold a constant vector CONSTRUCTOR to VECTOR_CST.   
       If we couldn't fold the RHS, hand over to the generic
       fold routines.   


       Strip away useless type conversions.  Both the NON_LVALUE_EXPR
       that may have been added by fold, and "useless" type
       conversions that might now be apparent due to propagation.   
           If the operation was a conversion do _not_ mark a
           resulting constant with TREE_OVERFLOW if the original
           constant was not.  These conversions have implementation
           defined behavior and retaining the TREE_OVERFLOW flag
           here would confuse later passes such as VRP.   
     Try to canonicalize for boolean-typed X the comparisons
     X == 0, X == 1, X != 0, and X != 1.   
         Check whether the comparison operands are of the same boolean
         type as the result type is.
         Check that second operand is an integer-constant with value
         one or zero.   
             X == 0 and X != 1 is a logical-not.of X
             X == 1 and X != 0 is X   
             Only for one-bit precision typed X the transformation
             !X -> ~X is valied.   
             Otherwise we use !X -> X ^ 1.   
     Try to fold a conditional expression.   
             This is actually a conditional expression, not a GIMPLE
             conditional statement, however, the valid_gimple_rhs_p
             test still applies.   
static bool fold_gimple_cond ( )
static

Attempt to fold a conditional statement. Return true if any changes were made. We only attempt to fold the condition expression, and do not perform any transformation that would require alteration of the cfg. It is assumed that the operands have been previously folded.

References cfun, gcc_assert, gimple_build_nop(), gimple_call_lhs(), gimple_in_ssa_p(), gimple_seq_empty_p(), gimplify_and_add(), gsi_replace(), gsi_stmt(), gimplify_ctx::into_ssa, is_gimple_call(), NULL, pop_gimplify_context(), push_gimplify_context(), release_defs(), and unlink_stmt_vdef().

static tree fold_nonarray_ctor_reference ( tree  type,
tree  ctor,
unsigned HOST_WIDE_INT  offset,
unsigned HOST_WIDE_INT  size,
tree  from_decl 
)
static

CTOR is CONSTRUCTOR of an aggregate or vector. Fold reference of type TYPE and size SIZE to the memory at bit OFFSET.

     Variable sized objects in static constructors makes no sense,
     but field_size can be NULL for flexible array members.   
     Compute bit offset of the field.   
     Compute bit offset where the field ends.   
     Is there any overlap between [OFFSET, OFFSET+SIZE) and
     [BITOFFSET, BITOFFSET_END)?   
         We do have overlap.  Now see if field is large enough to
         cover the access.  Give up for accesses spanning multiple
         fields.   
 When memory is not explicitely mentioned in constructor, it is 0.   
bool fold_stmt ( )

Fold the statement pointed to by GSI. In some cases, this function may replace the whole statement with a new one. Returns true iff folding makes any changes. The statement pointed to by GSI should be in valid gimple form but may be in unfolded state as resulting from for example constant propagation which can produce *&x = 0.

static bool fold_stmt_1 ( )
static

Worker for both fold_stmt and fold_stmt_inplace. The INPLACE argument distinguishes both cases.

 Fold the main computation performed by the statement.   
       First canonicalize operand order.  This avoids building new
       trees if this is the only thing fold would later do.   
     Fold *& in asm operands.   
 Fold *& on the lhs.   

References gimple_asm_output_op(), maybe_fold_reference(), REFERENCE_CLASS_P, TREE_PURPOSE, TREE_STRING_POINTER, and TREE_VALUE.

bool fold_stmt_inplace ( )

Perform the minimal folding on statement *GSI. Only operations like &x created by constant propagation are handled. The statement cannot be replaced with a new one. Return true if the statement was changed, false otherwise. The statement *GSI should be in valid gimple form but may be in unfolded state as resulting from for example constant propagation which can produce *&x = 0.

References gimple_assign_rhs_code(), integer_nonzerop(), integer_zerop(), is_gimple_assign(), operand_equal_p(), and SSA_NAME_DEF_STMT.

static tree fold_string_cst_ctor_reference ( tree  type,
tree  ctor,
unsigned HOST_WIDE_INT  offset,
unsigned HOST_WIDE_INT  size 
)
static

CTOR is STRING_CST. Fold reference of type TYPE and size SIZE to the memory at bit OFFSET.

We do only simple job of folding byte accesses.

Folding const char a[20]="hello"; return a[10];

might lead to offset greater than string length. In this case we know value is either initialized to 0 or out of bounds. Return 0 in both cases.

static tree get_base_constructor ( tree  base,
HOST_WIDE_INT bit_offset,
tree(*)(tree valueize 
)
static

See if we can find constructor defining value of BASE. When we know the consructor with constant offset (such as base is array[40] and we do know constructor of array), then BIT_OFFSET is adjusted accordingly.

As a special case, return error_mark_node when constructor is not explicitly available, but it is known to be zero such as 'static const int a;'.

Get a CONSTRUCTOR. If BASE is a VAR_DECL, get its DECL_INITIAL. If BASE is a nested reference into another ARRAY_REF or COMPONENT_REF, make a recursive call to resolve the inner reference.

       Our semantic is exact opposite of ctor_for_folding;
       NULL means unknown, while error_mark_node is 0.   
static bool get_maxval_strlen ( )
static

Return the string length, maximum string length or maximum value of ARG in LENGTH. If ARG is an SSA name variable, follow its use-def chains. If LENGTH is not NULL and, for TYPE == 0, its value is not equal to the length we determine or if we are unable to determine the length or value, return false. VISITED is a bitmap of visited variables. TYPE is 0 if string length should be returned, 1 for maximum string length and 2 for maximum value ARG can have.

We can end up with &(*iftmp_1)[0] here as well, so handle it.   
 If ARG is registered for SSA update we cannot look at its defining
 statement.   


 If we were already here, break the infinite cycle.   
       The RHS of the statement defining VAR must either have a
       constant length or come from another SSA_NAME with a constant
       length.   
         All the arguments of the PHI node must have the same constant
         length.   
           If this PHI has itself as an argument, we cannot
           determine the string length of this argument.  However,
           if we can find a constant string length for the other
           PHI args then we can still be sure that this is a
           constant string length.  So be optimistic and just
           continue with the next argument.   
tree get_symbol_constant_value ( )

If SYM is a constant variable with known value, return the value. NULL_TREE is returned otherwise.

Variables declared 'const' without an initializer have zero as the initializer if they may not be overridden at link or run time.

tree gimple_extract_devirt_binfo_from_cst ( )

Return a binfo to be used for devirtualization of calls based on an object represented by a declaration (i.e. a global or automatically allocated one) or NULL if it cannot be found or is not safe. CST is expected to be an ADDR_EXPR of such object or the function will return NULL. Currently it is safe to use such binfo only if it has no base binfo (i.e. no ancestors) EXPECTED_TYPE is type of the class virtual belongs to.

Find the sub-object the constant actually refers to and mark whether it is an artificial one (as opposed to a user-defined one).

 Artificial sub-objects are ancestors, we do not want to use them for
 devirtualization, at least not here.   
tree gimple_fold_builtin ( )

Fold builtin call in statement STMT. Returns a simplified tree. We may return a non-constant expression, including another call to a different function and with different arguments, e.g., substituting memcpy for strcpy when the string length is known. Note that some builtins expand into inline code that may not be valid in GIMPLE. Callers must take care.

 First try the generic builtin folder.  If that succeeds, return the
 result directly.   
 Ignore MD builtins.   
 Give up for always_inline inline builtins until they are
 inlined.   
 If the builtin could not be folded, and it has no argument list,
 we're done.   
 Limit the work only for builtins we know how to simplify.   
 Try to use the dataflow information gathered by the CCP process.   
         If the result is not a valid gimple value, or not a cast
         of a valid gimple value, then we cannot use the result.   
static bool gimple_fold_call ( )
static

Attempt to fold a call statement referenced by the statement iterator GSI. The statement may be replaced by another statement, e.g., if the call simplifies to a constant value. Return true if any changes were made. It is assumed that the operands have been previously folded.

 Fold *& in call arguments.   
 Check for virtual calls that became direct calls.   
 Check for builtins that CCP can handle using information not
 available in the generic fold routines.   
tree gimple_fold_indirect_ref ( )

Given a pointer value OP0, return a simplified version of an indirection through OP0, or NULL_TREE if no simplification is possible. Note that the resulting type may be different from the type pointed to in the sense that it is still compatible from the langhooks point of view.

      &p => p  
      (foo *)&fooarray => fooarray[0]  
      (foo *)&complexfoo => __real__ complexfoo  
      (foo *)&vectorfoo => BIT_FIELD_REF<vectorfoo,...>  
  (p + CST) -> ...   
     ((foo*)&vectorfoo)[1] -> BIT_FIELD_REF<vectorfoo,...>  
     ((foo*)&complexfoo)[1] -> __imag__ complexfoo  
      (p + CST) -> MEM_REF <p, CST>.   
  (foo *)fooarrptr => (*fooarrptr)[0]  
tree gimple_fold_stmt_to_constant ( gimple  stmt,
tree(*)(tree valueize 
)

Fold STMT to a constant using VALUEIZE to valueize SSA names. Returns NULL_TREE if folding to a constant is not possible, otherwise returns a constant according to is_gimple_min_invariant.

Referenced by check_array_ref().

tree gimple_fold_stmt_to_constant_1 ( gimple  stmt,
tree(*)(tree valueize 
)

Fold STMT to a constant using VALUEIZE to valueize SSA names.

Either NULL_TREE, a simplified but non-constant or a constant is returned.

??? This should go into a gimple-fold-inline.h file to be eventually privatized with the single valueize function used in the various TUs to avoid the indirect function call overhead.

If the RHS is an SSA_NAME, return its known constant value,
if any.   
             Handle propagating invariant addresses into address
             operations.   


             Handle unary operators that can appear in GIMPLE form.
             Note that we know the single operand must be a constant,
             so this should almost always return a simplified RHS.   
             Conversions are useless for CCP purposes if they are
             value-preserving.  Thus the restrictions that
             useless_type_conversion_p places for restrict qualification
             of pointer types should not apply here.
             Substitution later will only substitute to allowed places.   
             Handle binary operators that can appear in GIMPLE form.   
             Translate &x + CST into an invariant form suitable for
             further propagation.   
             Handle ternary operators that can appear in GIMPLE form.   
             Fold embedded expressions in ternary codes.   
         No folding yet for these functions.   
             fold_call_expr wraps the result inside a NOP_EXPR.   
tree gimple_get_virt_method_for_binfo ( )

Return a declaration of a function which an OBJ_TYPE_REF references. TOKEN is integer form of OBJ_TYPE_REF_TOKEN of the reference expression. KNOWN_BINFO carries the binfo describing the true type of OBJ_TYPE_REF_OBJECT(REF).

 If there is no virtual methods table, leave the OBJ_TYPE_REF alone.   
 The virtual tables should always be born with constructors.
 and we always should assume that they are avaialble for
 folding.  At the moment we do not stream them in all cases,
 but it should never happen that ctor seem unreachable.   
 When cgraph node is missing and function is not public, we cannot
 devirtualize.  This can happen in WHOPR when the actual method
 ends up in other partition, because we found devirtualization
 possibility too late.   
 Make sure we create a cgraph node for functions we'll reference.
 They can be non-existent if the reference comes from an entry
 of an external vtable for example.   

References BITS_PER_UNIT, bitsize_int, build4, fold_build1, fold_build3, host_integerp(), NULL_TREE, POINTER_TYPE_P, size_zero_node, STRIP_NOPS, TREE_CODE, tree_low_cst(), TREE_OPERAND, TREE_TYPE, TYPE_DOMAIN, TYPE_MIN_VALUE, TYPE_SIZE, TYPE_VECTOR_SUBPARTS, and useless_type_conversion_p().

Referenced by maybe_record_node().

bool gimple_val_nonnegative_real_p ( )

Return true iff VAL is a gimple expression that is known to be non-negative. Restricted to floating-point inputs.

 Use existing logic for non-gimple trees.   
 Currently we look only at the immediately defining statement
 to make this determination, since recursion on defining 
 statements of operands can lead to quadratic behavior in the
 worst case.  This is expected to catch almost all occurrences
 in practice.  It would be possible to implement limited-depth
 recursion if important cases are lost.  Alternatively, passes
 that need this information (such as the pow/powi lowering code
 in the cse_sincos pass) could be revised to provide it through
 dataflow propagation.   
     See fold-const.c:tree_expr_nonnegative_p for additional
     cases that could be handled with recursion.   
         Always true for floating-point operands.   
         True if the two operands are identical (since we are
         restricted to floating-point inputs).   
             sqrt(-0.0) is -0.0, and sqrt is not defined over other
             nonnegative inputs.   
             True if the second argument is an even integer.   
             True if the second argument is an even integer-valued
             real.   

References fold_build1, tree_int_cst_equal(), TREE_OPERAND, and TYPE_SIZE_UNIT.

void gimplify_and_update_call_from_tree ( )

Convert EXPR into a GIMPLE value suitable for substitution on the RHS of an assignment. Insert the necessary statements before iterator *SI_P. The statement at *SI_P, which must be a GIMPLE_CALL is replaced. If the call is expected to produces a result, then it is replaced by an assignment of the new RHS to the result variable. If the result is to be ignored, then the call is replaced by a GIMPLE_NOP. A proper VDEF chain is retained by making the first VUSE and the last VDEF of the whole sequence be the same as the replaced statement and using new SSA names for stores in between.

We can end up with folding a memcpy of an empty class assignment
which gets optimized away by C++ gimplification.   
 First iterate over the replacement statements backward, assigning
 virtual operands to their defining statements.   


 Second iterate over the statements forward, assigning virtual
 operands to their uses.   
     If the new statement possibly has a VUSE, update it with exact SSA
     name we know will reach this one.   
 If the new sequence does not do a store release the virtual
 definition of the original statement.   
 Finally replace the original statement with the sequence.   
tree maybe_fold_and_comparisons ( enum tree_code  code1,
tree  op1a,
tree  op1b,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)

Try to simplify the AND of two comparisons, specified by (OP1A CODE1 OP1B) and (OP2B CODE2 OP2B), respectively. If this can be simplified to a single expression (without requiring introducing more SSA variables to hold intermediate values), return the resulting tree. Otherwise return NULL_TREE. If the result expression is non-null, it has boolean type.

tree maybe_fold_or_comparisons ( enum tree_code  code1,
tree  op1a,
tree  op1b,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)

Try to simplify the OR of two comparisons, specified by (OP1A CODE1 OP1B) and (OP2B CODE2 OP2B), respectively. If this can be simplified to a single expression (without requiring introducing more SSA variables to hold intermediate values), return the resulting tree. Otherwise return NULL_TREE. If the result expression is non-null, it has boolean type.

static tree maybe_fold_reference ( )
static

Subroutine of fold_stmt. We perform several simplifications of the memory reference tree EXPR and make sure to re-gimplify them properly after propagation of constant addresses. IS_LHS is true if the reference is supposed to be an lvalue.

 Canonicalize MEM_REFs invariant address operand.  Do this first
 to avoid feeding non-canonical MEM_REFs elsewhere.   
 Fold back MEM_REFs to reference trees.   
     We have to look out here to not drop a required conversion
     from the rhs to the lhs if is_lhs, but we don't have the
     rhs here to verify that.  Thus require strict type
     compatibility.   

Referenced by fold_stmt_1().

static tree or_comparisons_1 ( enum tree_code  code1,
tree  op1a,
tree  op1b,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Try to simplify the OR of two comparisons defined by (OP1A CODE1 OP1B) and (OP2A CODE2 OP2B), respectively. If this can be done without constructing an intermediate value, return the resulting tree; otherwise NULL_TREE is returned. This function is deliberately asymmetric as it recurses on SSA_DEFs in the first comparison but not the second.

 First check for ((x CODE1 y) OR (x CODE2 y)).   
     Result will be either NULL_TREE, or a combined comparison.   
 Likewise the swapped case of the above.   
     Result will be either NULL_TREE, or a combined comparison.   
 If both comparisons are of the same value against constants, we might
 be able to merge them.   
     If we have (op1a != op1b), we should either be able to
     return that or TRUE, depending on whether the constant op1b
     also satisfies the other comparison against op2b.   
     Likewise if the second comparison is a != comparison.   
     See if an equality test is redundant with the other comparison.   
     Chose the less restrictive of two < or <= comparisons.   
     Likewise chose the less restrictive of two > or >= comparisons.   
     Check for singleton ranges.   
     Check for less/greater pairs that don't restrict the range at all.   
 Perhaps the first comparison is (NAME != 0) or (NAME == 1) where
 NAME's definition is a truth value.  See if there are any simplifications
 that can be done against the NAME's definition.   
         Try to simplify by copy-propagating the definition.   
         If every argument to the PHI produces the same result when
         ORed with the second comparison, we win.
         Do not do this unless the type is bool since we need a bool
         result here anyway.   
                 If this PHI has itself as an argument, ignore it.
                 If all the other args produce the same result,
                 we're still OK.   
                     In simple cases we can look through PHI nodes,
                     but we have to be careful with loops.
                     See PR49073.   

References boolean_type_node, and fold_build2.

static tree or_var_with_comparison ( tree  var,
bool  invert,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Helper function for or_comparisons_1: try to simplify the OR of the ssa variable VAR with the comparison specified by (OP2A CODE2 OP2B). If INVERT is true, invert the value of VAR before doing the OR. Return NULL_EXPR if we can't simplify this to a single expression.

We can only deal with variables whose definitions are assignments.

 If we have an inverted comparison, apply DeMorgan's law and rewrite
 !var OR (op2a code2 op2b) => !(var AND !(op2a code2 op2b))
 Then we only have to consider the simpler non-inverted cases.   

References boolean_true_node, integer_onep(), and integer_zerop().

static tree or_var_with_comparison_1 ( gimple  stmt,
enum tree_code  code2,
tree  op2a,
tree  op2b 
)
static

Try to simplify the OR of the ssa variable defined by the assignment STMT with the comparison specified by (OP2A CODE2 OP2B). Return NULL_EXPR if we can't simplify this to a single expression.

 Check for identities like (var OR (var != 0)) => true .   
 If the definition is a comparison, recurse on it.   
 If the definition is an AND or OR expression, we may be able to
 simplify by reassociating.   
     Check for boolean identities that don't require recursive examination
     of inner1/inner2:
     inner1 OR (inner1 OR inner2) => inner1 OR inner2 => var
     inner1 OR (inner1 AND inner2) => inner1
     !inner1 OR (inner1 OR inner2) => true
     !inner1 OR (inner1 AND inner2) => !inner1 OR inner2
     Next, redistribute/reassociate the OR across the inner tests.
     Compute the first partial result, (inner1 OR (op2a code op2b))   
         Handle the OR case, where we are reassociating:
         (inner1 OR inner2) OR (op2a code2 op2b)
         => (t OR inner2)
         If the partial result t is a constant, we win.  Otherwise
         continue on to try reassociating with the other inner test.   
         Handle the AND case, where we are redistributing:
         (inner1 AND inner2) OR (op2a code2 op2b)
         => (t AND (inner2 OR (op2a code op2b)))   
         Save partial result for later.   
     Compute the second partial result, (inner2 OR (op2a code op2b))  
         Handle the OR case, where we are reassociating:
         (inner1 OR inner2) OR (op2a code2 op2b)
         => (inner1 OR t)
         => (t OR partial)   
             If both are the same, we can apply the identity
             (x OR x) == x.   
         Handle the AND case, where we are redistributing:
         (inner1 AND inner2) OR (op2a code2 op2b)
         => (t AND (inner1 OR (op2a code2 op2b)))
         => (t AND partial)   
                 We already got a simplification for the other
                 operand to the redistributed AND expression.  The
                 interesting case is when at least one is true.
                 Or, if both are the same, we can apply the identity
                 (x AND x) == x.   

References boolean_true_node, integer_onep(), integer_zerop(), and same_bool_result_p().

static bool same_bool_comparison_p ( const_tree  expr,
enum tree_code  code,
const_tree  op1,
const_tree  op2 
)
static

Check to see if a boolean expression EXPR is logically equivalent to the comparison (OP1 CODE OP2). Check for various identities involving SSA_NAMEs.

 The obvious case.   
 Check for comparing (name, name != 0) and the case where expr
 is an SSA_NAME with a definition matching the comparison.   
 If op1 is of the form (name != 0) or (name == 0), and the definition
 of name is a comparison, recurse.   
static bool same_bool_result_p ( )
static

Check to see if two boolean expressions OP1 and OP2 are logically equivalent.

 Simple cases first.   
 Check the cases where at least one of the operands is a comparison.
 These are a bit smarter than operand_equal_p in that they apply some
 identifies on SSA_NAMEs.   
 Default case.   

References and_comparisons_1(), boolean_false_node, gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), integer_nonzerop(), integer_zerop(), NULL_TREE, tcc_comparison, TREE_CODE, TREE_CODE_CLASS, and TREE_TYPE.

Referenced by or_var_with_comparison_1().