diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-08-27 20:08:34 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-08-27 20:08:34 +0000 |
commit | 11ca2971e88f37dc1b40f00542cb6228e255fee4 (patch) | |
tree | a5f723b13e06407de3cda365680ad038ae39df81 | |
parent | 48c82400edc6244073fa90dcd805b23e0d077d79 (diff) | |
download | bcm5719-llvm-11ca2971e88f37dc1b40f00542cb6228e255fee4.tar.gz bcm5719-llvm-11ca2971e88f37dc1b40f00542cb6228e255fee4.zip |
InstSimplify: Don't simplify gep X, (Y-X) to Y if types differ
It's incorrect to perform this simplification if the types differ.
A bitcast would need to be inserted for this to work.
This fixes PR20771.
llvm-svn: 216597
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstSimplify/gep.ll | 14 |
2 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 118579d5b72..9f3b2876afe 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2837,7 +2837,8 @@ static Value *SimplifyGEPInst(ArrayRef<Value *> Ops, const Query &Q, unsigned) { return Constant::getNullValue(GEPTy); Value *Temp; if (match(P, m_PtrToInt(m_Value(Temp)))) - return Temp; + if (Temp->getType() == GEPTy) + return Temp; return nullptr; }; diff --git a/llvm/test/Transforms/InstSimplify/gep.ll b/llvm/test/Transforms/InstSimplify/gep.ll index d1704bf80bc..49a97f133ce 100644 --- a/llvm/test/Transforms/InstSimplify/gep.ll +++ b/llvm/test/Transforms/InstSimplify/gep.ll @@ -64,3 +64,17 @@ define i64* @test6(i64* %b) { ; CHECK-LABEL: @test6 ; CHECK-NEXT: ret i64* null } + +define i8* @test7(i8* %b, i8** %e) { + %e_ptr = ptrtoint i8** %e to i64 + %b_ptr = ptrtoint i8* %b to i64 + %sub = sub i64 %e_ptr, %b_ptr + %gep = getelementptr inbounds i8* %b, i64 %sub + ret i8* %gep +; CHECK-LABEL: @test7 +; CHECK-NEXT: ptrtoint +; CHECK-NEXT: ptrtoint +; CHECK-NEXT: sub +; CHECK-NEXT: getelementptr +; CHECK-NEXT: ret +} |