[PATCH] D47198: [InstCombine] Replace malloc+strcpy with malloc+memcpy

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 22 11:59:10 PDT 2018


xbolva00 added a comment.

In https://reviews.llvm.org/D47198#1108283, @efriedma wrote:

> What does the malloc have to do with this transform?  The transform here is just `strcpy(d, s)` -> `memcpy(d, s, strlen(s)+1)`, where `strlen(s)` is free because we can CSE it with the previous call.  I guess in general, you can transform `strcpy(malloc(strlen(s)+1), s)` to strdup, but that's not what you're doing.
>
> Also, you're making the same mistake *again*: you're not checking whether the string is modified between the strlen and the strcpy.


Ah yes, sure (why I still think that if value comes from malloc, it cannot modified between, sigh, sorry) :/ 
Too bad that helper function "isModifiedBetween" cannot be used here.

But with these transformations (malloc-memset, malloc-strcpy), arent we just transforming part of InstCombine to DSE? Are all these transformations legal there, I mean the right place for them?

If yes, I could rework this patch for DSE after some time.


https://reviews.llvm.org/D47198





More information about the llvm-commits mailing list