[llvm-dev] Constants propagation into printf format string

Dávid Bolvanský via llvm-dev llvm-dev at lists.llvm.org
Thu May 17 15:53:32 PDT 2018


Hello,

I was thinking about a new possible simplification in InstCombine which
would transform code like this:

const char * NAME = "Prog";

void printer(char **arr, int len) {
  for (int i = 0; i < len; ++i) {
    printf("%s: %s", NAME, arr[i]);
  }
}

into

void printer(char **arr, int len) {
  for (int i = 0; i < len; ++i) {
    printf("Prog: %s", arr[i]);
  }
}

This transformation would take constant strings/integers/chars and put them
to the format string.

In the example I used "printf" but it could be applied also for
fprintf and sprintf.

Do you consider this as good to be implemented? Or not worth to do at all?

I implemented it some time ago personally just for fun to try it. I would
reimplement it and send a patch to LLVM if any interest.

Ideas? Complains? Suggestions?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180518/64adf876/attachment.html>


More information about the llvm-dev mailing list