message: [XLA] Don't count ops which run "faster than optimal" in our "seconds above optimum" total.
  In other words, for the purposes of calculating totals, let the "true optimum"
  be the smaller of the estimated optimum and the actual runtime.
diff: @@ -99,13 +99,20 @@ string HumanReadableProfileBuilder::ToString() const {
  bytes_per_sec, bytes_per_cycle, op.name);
  };
  - float optimal_seconds_sum = 0.0;
  + double optimal_seconds_sum = 0;
  int64 total_flops = 0.;
  int64 total_transcendentals = 0.;
  int64 total_bytes = 0;
  for (const auto& op : op_infos_) {
  if (op.optimal_seconds > 0) {
  - optimal_seconds_sum += op.optimal_seconds;
  + // An op can run faster than the estimated optimum. For example, we might
  + // estimate a fusion's speed by looking at the size of its operands and
  + // result, but perhaps the fusion doesn't read the entirety of all of its
  + // inputs. For the purposes of summing the instructions' optimal speeds,
  + // we treat the "optimum" as the smallest of either the estimated optimum
  + // and the actual speed.
  + optimal_seconds_sum +=
  + std::min(double{op.optimal_seconds}, CyclesToSeconds(op.cycles));
  }
  total_flops += std::max(op.flop_count, int64{0});
  total_transcendentals += std::max(op.transcendental_count, int64{0});
  @@ -116,7 +123,7 @@ string HumanReadableProfileBuilder::ToString() const {
  print_op({is_entry_computation_ ? "[total] [entry]" : "[total]", "[total]",
  /*category=*/"", total_cycles_, total_flops, total_transcendentals,
  - total_bytes, optimal_seconds_sum},
  + total_bytes, static_cast<float>(optimal_seconds_sum)},
  /*is_total=*/true);
  // Sort ops in decreasing order of cycles, and print them.
  @@ -157,8 +164,10 @@ string HumanReadableProfileBuilder::ToString() const {
  entry.text = op.name;
  entry.short_text = op.short_name;
  entry.category_text = op.category;
  - entry.metric =
  - CyclesToMicroseconds(op.cycles) - op.optimal_seconds * 1e6;
  + // Ignore ops that run faster than the estimated optimal here, as we do
  + // when calculating optimal_seconds_sum.
  + entry.metric = std::max(
  + 0., CyclesToMicroseconds(op.cycles) - op.optimal_seconds * 1e6);
  total_discrepancy_in_microseconds += entry.metric;
  table.AddEntry(std::move(entry));
  }
  