On Mon, Feb 7, 2022 at 3:32 PM Andrew MacLeod via Gcc-patches
<[email protected]> wrote:
>
> This patch adds the ability to register side effects within a block to
> ranger. This is currently only for tracking non-null values.
>
> the rvrp_folder performs a DOM walk and then attempts to simplify and
> the fold each stmt during the walk. This patch adds a call to
> register_side_effects() to record any effects the stmt might have before
> returning.
>
> This checks if the non-null property is set for any ssa-names on the
> statement, and if they are, moves the state to only non-null for the
> block... This allows us to adjust the property within the block as we
> do the DOM walk. All further queries within the block will then come
> back as non-null. ALl other queries will be from outside the block, so
> they will see the same results anyway.
>
> Unfortunately, none of the non-null routines in gimple.cc appear to work
> "in bulk", but rather, on a specific tree-ssa operand request at a
> time. For this patch, I need to scan the entire statement looking for
> any operand that is nonnull (or the performance impact is awful).
In tree.cc we have get_nonnull_args which you'd pass the
gimple_call_fntype, its expense is allocating a bitmap (if any arg is nonnull)
which you'd then need to iterate over and free. I think that's an OK
overhead for not duplicating the walk?
> I took the code in the various infer_nonnull routines, and packed it all
> together into the two routines block_apply_nonnull &&
> infer_nonnull_call_attributes, which basically perform the same
> functionality as infer_nonnull_range_by_dereference and
> infer_nonnull_range_by_attribute, only on all the operands at once. I
> think its right, but you may want to have a look. I intend to leverage
> this code in GCC13 for a more generalized range_after_stmt mechanism
> that will do away with the immediate-use visits of the current non-null
+void
+non_null_ref::block_apply_nonnull (gimple *s)
+{
+ if (!flag_delete_null_pointer_checks)
+ return;
+ if (is_a<gphi *> (s))
+ return;
+ if (gimple_code (s) == GIMPLE_ASM || gimple_clobber_p (s))
+ return;
+ if (is_a<gcall *> (s))
+ {
+ infer_nonnull_call_attributes (as_a<gcall *> (s));
+ return;
+ }
+ walk_stmt_load_store_ops (s, (void *)this, non_null_loadstore,
+ non_null_loadstore);
Both ASM and calls can have pointer dereferences embedded so
I wonder whether you should do the walk_stmt_load_store_ops
anyway. Note that any exceptional control flow (EH or abnormal)
will not have realized the outputs on a stmt (LHS of call, outputs
of asms), so nonnull carries over only across fallthru or conditional
edges.
I suppose realizing the LHS could be postponed for GCC 13, for
calls you could still walk loads so you get the non-nullness of
aggregate arguments like foo (*p) after the stmt.
But you can of course do all this for GCC 13 only.
> This patch also has zero effect on generated code as none of the
> nonnull_deref_p() queries make use of the new granularity available
> yet. It does set the table for the next patch. Performance impact of
> this is also marginal, about a 1% hit to EVRP/VRP.
>
> Bootstraps with no regressions. OK for trunk?
>
> Andrew
>
>
>