[PATCH] D13358: InstSimplify: Fold comparisons between allocas and arguments under certain circumstances
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 11:20:02 PDT 2015
hans created this revision.
hans added reviewers: sunfish, reames, hfinkel, majnemer, aaron.ballman.
hans added subscribers: llvm-commits, hansw.
This will allow us to optimize code such as:
int f(int *p) {
int x;
return p == &x;
}
However, it can only be done under certain circumstances. As the comment above computePointerICmp() points out, even though p and &x cannot alias, the comparison must still return true if the pointer representations are equal. If a user successfully passes in a p that's a correct guess for &x, it should return true, even though p is an invalid pointer.
This patch argues that if the address of the alloca isn't observable outside the function, the function can act as-if the address is impossible to guess from the outside. The tricky part is keeping the act consistent: if we fold p == &x to false in one place, we must make sure to fold any other comparisons based on those pointers similarly.
Let me know what you think.
http://reviews.llvm.org/D13358
Files:
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/compare.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13358.36273.patch
Type: text/x-patch
Size: 7703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151001/20bfb783/attachment.bin>
More information about the llvm-commits
mailing list