alive2 verification : https://alive2.llvm.org/ce/z/Po2nL4
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
2797–2798 | Variable names in LLVM start with an uppercase letter. | |
2800 | This condition isn't wrong, but it's also not as accurate as it could be. Let's say LHSSize = 4, LHSOffset = 0, RHSSize = 2, RHSOffset = 2 with LHSOffset - RHSOffset = -2. These can be equal. Then consider LHSSize = 4, LHSOffset = 2, RHSSize = 2, RHSOffset = 0 with LHSOffset - RHSOffset = 2. These cannot be equal. As you can see, the sign of the result matters and we should not just take the absolute value. I believe the condition should be Dist.isNonNegative() ? Dist.ult(LHSSize) : (-Dist).ult(RHSSize). |
updated the code according to nikic's comment.
This condition isn't wrong, but it's also not as accurate as it could be.
Let's say LHSSize = 4, LHSOffset = 0, RHSSize = 2, RHSOffset = 2 with LHSOffset - RHSOffset = -2. These can be equal.
Then consider LHSSize = 4, LHSOffset = 2, RHSSize = 2, RHSOffset = 0 with LHSOffset - RHSOffset = 2. These cannot be equal.
As you can see, the sign of the result matters and we should not just take the absolute value.
I believe the condition should be Dist.isNonNegative() ? Dist.ult(LHSSize) : (-Dist).ult(RHSSize).
This mostly looks good to me.
As implemented, there was a potential issue here where you would get an assertion failure due to different bit widths if certain address space casts were involved. I've opted to make that impossible in https://github.com/llvm/llvm-project/commit/793eb0c0e4ffadc1cfebcda0c0cb1bcc2311def2 rather than have you introduce extra extensions here.
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
2798 | Combine declaration and initialization. | |
llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll | ||
219 | We should have some additional test cases that work on differently-sized allocas, to show that the check is asymmetric. E.g. allocas with size 2 and 4 with effective diffs 2 and -2. |
there was such a problem. I didn't know!! thanks for letting me.
llvm/lib/Analysis/InstructionSimplify.cpp | ||
---|---|---|
2797–2798 | shoud I have to declare and assign Dist at the same time? |
LGTM. If you need me to commit this for you, can you please share the Name <email> to use for attribution?
sure, I use email kese111@gmail.com and name is Hanbum Park!
llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll | ||
---|---|---|
219 | added test cases! |
Variable names in LLVM start with an uppercase letter.