Allow iterating through SelectInst use of the alloca when
checking if it is only ever overwritten from constant memory.
Recursively determine if the SelectInst is replacable and insert
it into the Worklist if so. Finally, define a new SelectInst to
replace the old one, with both of it's values replaced according
to the WorkMap.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | ||
---|---|---|
327 | IC.InsertNewInstWith should take care of debug info, but you're dropping any other instruction metadata that was attached |
- Rebased against the latest revision.
- Check if the true and false values of SelectInst are already in the Worklist before inserting the SelectInst itself into the Worklist.
- Define a new SelectInst while preserving the attached MetaData.
- Revise tests
llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll | ||
---|---|---|
375 ↗ | (On Diff #490302) | Need to be erased since it's never used. |
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | ||
---|---|---|
64–65 | Handling for SelectInst should use same logic as PHINode (with IsOffset = true). Can you please add a test with a memcpy on the select result, which should not get transformed? |
- isOffset = true for SelectInst in isOnlyCopiedFromConstantMemory(..)
- Added a test where memcpy is performed upon the result of a SelectInst
- Removed the intrinsic in the test which is never used.
This is missing a test with different address space and removed alloca, but otherwise looks fine.
Is there one? I can't think of a test case where the source and dest of a memcpy are in different address spaces and the alloca is removed.
- Added a test with varying addrspaces across the source and dest of a memcpy and the alloca is eliminated.
llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll | ||
---|---|---|
397–399 ↗ | (On Diff #490509) | Despite the change from 256 to 32 and your comment above, I stil get the same result. Some other instcombine optimization optimizes this function out apparently. |
Can you please rebase over https://github.com/llvm/llvm-project/commit/f61ee94470439c54499d43f0826cee04d99d5e9b? I think this should work. The problem was that we convert load of select into select of loads, so the select is outside the transform. Adding an extra GEP afterwards avoid this.
Something went wrong with the rebase. This should be the ptr-replace-alloca.ll from main with update_test_checks rerun.
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp | ||
---|---|---|
267 | Okay, I understand now why the new test case does not fold. Please switch this to the isAvailable() method added in https://github.com/llvm/llvm-project/commit/ed9806363beb1caf5265e75a64de904b60218093 and regenerate the test. I think then everything should work as expected. |
Thank you for the review Nikita, I will commit this patch as soon as the pre-merge checks complete.
Handling for SelectInst should use same logic as PHINode (with IsOffset = true). Can you please add a test with a memcpy on the select result, which should not get transformed?