From: Hans Wennborg Date: Tue, 31 Jan 2017 18:33:00 +0000 (+0000) Subject: Merging r293629: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6609175de16d00c59f11b358e96675933acfa8bf;p=llvm Merging r293629: ------------------------------------------------------------------------ r293629 | sbaranga | 2017-01-31 06:04:15 -0800 (Tue, 31 Jan 2017) | 15 lines [InstCombine] Make sure that LHS and RHS have the same type in transformToIndexedCompare If they don't have the same type, the size of the constant index would need to be adjusted (and this wouldn't be always possible). Alternatively we could try the analysis with the initial RHS value, which would guarantee that the two sides have the same type. However it is unlikely that in practice this would pass our transformation requirements. Fixes PR31808 (https://llvm.org/bugs/show_bug.cgi?id=31808). ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@293669 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 013159cde77..bca1304534b 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -884,6 +884,10 @@ static Instruction *transformToIndexedCompare(GEPOperator *GEPLHS, Value *RHS, if (!GEPLHS->hasAllConstantIndices()) return nullptr; + // Make sure the pointers have the same type. + if (GEPLHS->getType() != RHS->getType()) + return nullptr; + Value *PtrBase, *Index; std::tie(PtrBase, Index) = getAsConstantIndexedAddress(GEPLHS, DL); diff --git a/test/Transforms/InstCombine/indexed-gep-compares.ll b/test/Transforms/InstCombine/indexed-gep-compares.ll index 64dff271297..71afed438d1 100644 --- a/test/Transforms/InstCombine/indexed-gep-compares.ll +++ b/test/Transforms/InstCombine/indexed-gep-compares.ll @@ -188,3 +188,20 @@ bb10: declare i32 @__gxx_personality_v0(...) + +define i1 @test8(i64* %in, i64 %offset) { +entry: + + %ld = load i64, i64* %in, align 8 + %casti8 = inttoptr i64 %ld to i8* + %gepi8 = getelementptr inbounds i8, i8* %casti8, i64 %offset + %cast = bitcast i8* %gepi8 to i32** + %ptrcast = inttoptr i64 %ld to i32** + %gepi32 = getelementptr inbounds i32*, i32** %ptrcast, i64 1 + %cmp = icmp eq i32** %gepi32, %cast + ret i1 %cmp + + +; CHECK-LABEL: @test8( +; CHECK-NOT: icmp eq i32 %{{[0-9A-Za-z.]+}}, 1 +}