Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit 85e6f24

Browse files
committed
[MergeFuncs] Fix bug in merging GetElementPointers
GetElementPointers must have the first argument's type compared for structural equivalence. Previously the code erroneously compared the pointer's type, but this code was dead because all pointer types (of the same address space) are the same. The pointee must be compared instead (using the type stored in the GEP, not from the pointer type which will be erased anyway). Author: jrkoenig Reviewers: dschuff, nlewycky, jfb Subscribers: nlewycky, llvm-commits Differential revision: http://reviews.llvm.org/D12820 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247570 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e50e6f3 commit 85e6f24

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,8 @@ int FunctionComparator::cmpGEPs(const GEPOperator *GEPL,
10281028
if (GEPL->accumulateConstantOffset(DL, OffsetL) &&
10291029
GEPR->accumulateConstantOffset(DL, OffsetR))
10301030
return cmpAPInts(OffsetL, OffsetR);
1031-
if (int Res = cmpTypes(GEPL->getPointerOperand()->getType(),
1032-
GEPR->getPointerOperand()->getType()))
1031+
if (int Res = cmpTypes(GEPL->getSourceElementType(),
1032+
GEPR->getSourceElementType()))
10331033
return Res;
10341034

10351035
if (int Res = cmpNumbers(GEPL->getNumOperands(), GEPR->getNumOperands()))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: opt -mergefunc -S < %s | FileCheck %s
2+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3+
4+
; These should not be merged, the type of the GEP pointer argument does not have
5+
; the same stride.
6+
7+
%"struct1" = type <{ i8*, i32, [4 x i8] }>
8+
%"struct2" = type { i8*, { i64, i64 } }
9+
10+
define internal %struct2* @Ffunc(%struct2* %P, i64 %i) {
11+
; CHECK-LABEL: @Ffunc(
12+
; CHECK-NEXT: getelementptr
13+
; CHECK-NEXT: getelementptr
14+
; CHECK-NEXT: getelementptr
15+
; CHECK-NEXT: getelementptr
16+
; CHECK-NEXT: getelementptr
17+
; CHECK-NEXT: getelementptr
18+
; CHECK-NEXT: ret
19+
%1 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
20+
%2 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
21+
%3 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
22+
%4 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
23+
%5 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
24+
%6 = getelementptr inbounds %"struct2", %"struct2"* %P, i64 %i
25+
ret %struct2* %6
26+
}
27+
28+
29+
define internal %struct1* @Gfunc(%struct1* %P, i64 %i) {
30+
; CHECK-LABEL: @Gfunc(
31+
; CHECK-NEXT: getelementptr
32+
; CHECK-NEXT: getelementptr
33+
; CHECK-NEXT: getelementptr
34+
; CHECK-NEXT: getelementptr
35+
; CHECK-NEXT: getelementptr
36+
; CHECK-NEXT: getelementptr
37+
; CHECK-NEXT: ret
38+
%1 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
39+
%2 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
40+
%3 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
41+
%4 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
42+
%5 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
43+
%6 = getelementptr inbounds %"struct1", %"struct1"* %P, i64 %i
44+
ret %struct1* %6
45+
}
46+

0 commit comments

Comments
 (0)