The following syncs up LTO tree hashing and streaming of TYPE_MODE and DECL_MODE which long had a discrepancy for vector types and recently got special-casing of streaming for offloading. Failure to handle this results in less possible type merging to occur. Note the compare step will still use TYPE_MODE and DECL_MODE.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * lto-streamer-out.cc (hash_tree): Hash TYPE_MODE_RAW. When offloading hash modes as VOIDmode for aggregates and vectors. --- gcc/lto-streamer-out.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc index a055d12d6be..86d338461c0 100644 --- a/gcc/lto-streamer-out.cc +++ b/gcc/lto-streamer-out.cc @@ -1256,7 +1256,17 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) { - hstate.add_hwi (DECL_MODE (t)); + /* Similar to TYPE_MODE, avoid streaming out host-specific DECL_MODE + for aggregate type with offloading enabled, and while streaming-in + recompute appropriate DECL_MODE for accelerator. */ + if (lto_stream_offload_p + && (VAR_P (t) + || TREE_CODE (t) == PARM_DECL + || TREE_CODE (t) == FIELD_DECL) + && AGGREGATE_TYPE_P (TREE_TYPE (t))) + hstate.add_hwi (VOIDmode); + else + hstate.add_hwi (DECL_MODE (t)); hstate.add_flag (DECL_NONLOCAL (t)); hstate.add_flag (DECL_VIRTUAL_P (t)); hstate.add_flag (DECL_IGNORED_P (t)); @@ -1354,7 +1364,19 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map, if (CODE_CONTAINS_STRUCT (code, TS_TYPE_COMMON)) { - hstate.add_hwi (TYPE_MODE (t)); + /* For offloading, avoid streaming out TYPE_MODE for aggregate type since + it may be host-specific. For eg, aarch64 uses OImode for ARRAY_TYPE + whose size is 256-bits, which is not representable on accelerator. + Instead stream out VOIDmode, and while streaming-in, recompute + appropriate TYPE_MODE for accelerator. */ + if (lto_stream_offload_p + && (AGGREGATE_TYPE_P (t) || VECTOR_TYPE_P (t))) + hstate.add_hwi (VOIDmode); + /* for VECTOR_TYPE, TYPE_MODE reevaluates the mode using target_flags + not necessary valid in a global context. + Use the raw value previously set by layout_type. */ + else + hstate.add_hwi (TYPE_MODE_RAW (t)); /* TYPE_NO_FORCE_BLK is private to stor-layout and need no streaming. */ hstate.add_flag (TYPE_PACKED (t)); -- 2.43.0