diff --git a/hercules_opt/src/gcm.rs b/hercules_opt/src/gcm.rs index 462d10871565bfed9b351d2627c44af8ca778ffc..6d36e8ac2cd6c8fdff46f4e46b25a95e5b15db51 100644 --- a/hercules_opt/src/gcm.rs +++ b/hercules_opt/src/gcm.rs @@ -421,6 +421,9 @@ fn basic_blocks( // If the next node further up the dominator tree is in a shallower // loop nest or if we can get out of a reduce loop when we don't // need to be in one, place this data node in a higher-up location. + // Only do this is the node isn't a constant or undef. + let is_constant_or_undef = + function.nodes[id.idx()].is_constant() || function.nodes[id.idx()].is_undef(); let old_nest = loops .header_of(location) .map(|header| loops.nesting(header).unwrap()); @@ -441,7 +444,7 @@ fn basic_blocks( // loop use the reduce node forming the loop, so the dominator chain // will consist of one block, and this loop won't ever iterate. let currently_at_join = function.nodes[location.idx()].is_join(); - if shallower_nest || currently_at_join { + if !is_constant_or_undef && (shallower_nest || currently_at_join) { location = control_node; } }