This is the first of two patches to address PR46753. We basically allow
mem2reg to promote allocas that are used in doppable instructions, for
now that means llvm.assume. The uses of the alloca (or a bitcast or
zero offset GEP from there) are replaced by undef in the droppable
instructions.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
thank you for working on this
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp | ||
---|---|---|
347 | is there a reason you are not using dropDroppableUses here. replacing uses in an assume by undef is usually not a safe transformation. perhaps there is UB is not exploited for operand bundles but it is very likely to be exploited for the usual boolean argument of assume. |
just one nit
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp | ||
---|---|---|
324 | using dropDroppableUses this way is a bit weird since it is already doing a traversal through the uses but it is correct. maybe an API to drop a single use would be appropriate. |
llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp | ||
---|---|---|
324 | I'll look into it and update this. I'll commit it if it seems straight forward, post review if anyone disagrees. |
llvm/lib/IR/Value.cpp | ||
---|---|---|
197 ↗ | (On Diff #280542) | This seems like a dubious pattern; you're iterating over the entire use list of the value each time you call dropDroppableUsesByUser, which is likely a lot more expensive than iterating over the operand list of the assume. |
llvm/lib/IR/Value.cpp | ||
---|---|---|
197 ↗ | (On Diff #280542) | @jdoerfert @Tyker Any more thoughts on Eli's point? |
(I missed the comment, apologies)
llvm/lib/IR/Value.cpp | ||
---|---|---|
197 ↗ | (On Diff #280542) | I have no particular preference. Unclear what is better (over time). I'll propose a follow up patch that uses the assume operands instead. |
llvm/lib/IR/Value.cpp | ||
---|---|---|
197 ↗ | (On Diff #280542) | To be precise, my concern is that the overall algorithm is O(N^2) over the number of uses of the alloca. |
llvm/lib/IR/Value.cpp | ||
---|---|---|
197 ↗ | (On Diff #280542) | i agree with Eli, i tried express my concern about that in https://reviews.llvm.org/D83976?id=280542#inline-775547 |
using dropDroppableUses this way is a bit weird since it is already doing a traversal through the uses but it is correct.
maybe an API to drop a single use would be appropriate.