diff options
author | Hans Wennborg <hans@hanshq.net> | 2015-10-07 00:20:07 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2015-10-07 00:20:07 +0000 |
commit | f1f36517b7c6c17a132532db331461797892012c (patch) | |
tree | f93b9cf903d466e1bf0645d8b3895272fab735e0 /llvm/lib/Transforms/InstCombine/InstCombineInternal.h | |
parent | 534ff2caca13dec67a8507dbfb4a75c83f752a5e (diff) | |
download | bcm5719-llvm-f1f36517b7c6c17a132532db331461797892012c.tar.gz bcm5719-llvm-f1f36517b7c6c17a132532db331461797892012c.zip |
InstCombine: Fold comparisons between unguessable allocas and other pointers
This will allow us to optimize code such as:
int f(int *p) {
int x;
return p == &x;
}
as well as:
int *allocate(void);
int f() {
int x;
int *p = allocate();
return p == &x;
}
The folding can only be done under certain circumstances. Even though p and &x
cannot alias, the comparison must still return true if the pointer
representations are equal. If a user successfully generates a p that's a
correct guess for &x, comparison 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. To ensure that, we only fold when &x is involved
exactly once in comparison instructions.
Differential Revision: http://reviews.llvm.org/D13358
llvm-svn: 249490
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineInternal.h')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 9e58c7428bd..79cb5f25dc6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -281,6 +281,7 @@ public: ICmpInst::Predicate Pred); Instruction *FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, ICmpInst::Predicate Cond, Instruction &I); + Instruction *FoldAllocaCmp(ICmpInst &ICI, AllocaInst *Alloca, Value *Other); Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1, BinaryOperator &I); Instruction *commonCastTransforms(CastInst &CI); |