Diff Detail
Event Timeline
@xbolva00 please always always upload all the patches with the full context (-U99999)
test/Transforms/InstCombine/memset-1.ll | ||
---|---|---|
30 | There is no https://bugs.llvm.org/show_bug.cgi?id=45344 |
Yes, fixed now :D I am sorry for too many updated revisions, it is my first contribution to llvm :D
IIUC, these are 2 independent changes, so they should be split into separate patches:
- Handle the memset intrinsic identically to the way we handle the memset libcall. What about memset_chk()?
- Remove the hasOneUse() limitation on the malloc. The reason that's there is discussed in D16337 - the transform must be made safe from intermediate stores. This patch as-is will miscompile that pattern.
I've added tests at rL329412 and regenerated the check lines. Please fix/limit this patch and rebase.
Your patch https://reviews.llvm.org/rL329412 (@malloc_and_memset_intrinsic) needs to be updated after these two patches are applied.
I'm confused. This patch is supposed to show a calloc transform.
@malloc_and_memset_intrinsic has multiple uses of the malloc result, so the transform doesn't work there. Is there some other way to show the transform? If not, then sorry that I misunderstood, but we can't split the patches.
But D45381 just removes the one-use check and miscompiles @buffer_is_modified_then_memset. Why is that ok?
I closed D45381 & reupdated this patch, added test case. Test @buffer_is_modified_then_memset is ok now too.
If I apply this patch, the test case fails.
Do you understand the problem with the intervening store? You can't solve that by simply removing the one-use check.
I added solution.
Simply check any Instruction between malloc and memset if use value from malloc, if so, do not fold.
This transform really belongs in DeadStoreElimination, not here; it has the relevant logic and some similar transforms.
I mean the whole foldMallocMemset transform should be in DSE. I mean, arguably the transform isn't actually eliminating a dead store, but the code you need is very similar to eliminateNoopStore.
There is no https://bugs.llvm.org/show_bug.cgi?id=45344
You mean D45344?
Then it may be better not to use such a specific name.