[PATCH] D93838: [SCCP] Add Function Specialization pass

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 6 02:11:25 PDT 2021


ChuanqiXu added a comment.

The benefits of 505.mcf_r comes from the specialization for `spec_qsort`. Here is the signature of `spec_qsort`:

  void
  spec_qsort(void *a, size_t n, size_t es, cmp_t *cmp)

Here the `cmp_t*` is a function pointer. And there are lots of uses of cpp in `spec_qsort`. And `spec_qsort` is called in two places in `505.mcf_r`:

  spec_qsort(arcs_pointer_sorted[thread], new_arcs_array[thread], sizeof(arc_p),
                  (int (*)(const void *, const void *))arc_compare);
  spec_qsort(perm + 1, basket_sizes[thread], sizeof(BASKET*),
              (int (*)(const void *, const void *))cost_compare);

Both arc_compare and cost_compare are global functions. So here we can get the reason why function specialization benefits 505.mcf_r. It is converting the indirect call to direct call by function specialization and the direct call would be inlined further.

It looks like this pattern is usual in our daily work codes. However, I wonder what if there is multiple call site for `spec_qsort` with multiple global functions. It looks like the code now can't handle this situation, which is more usual in projects. I didn't ask for the change of cost model. I think we can made it in the future. This is just a sharing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93838/new/

https://reviews.llvm.org/D93838



More information about the llvm-commits mailing list