Skip to content

Commit

Permalink
Merging r312357:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
r312357 | davide | 2017-09-01 12:54:08 -0700 (Fri, 01 Sep 2017) | 9 lines

[TTI] Fix getGEPCost() for geps with a single operand.

Previously this would sporadically crash as TargetType
was never initialized. We special-case the single-operand
case returning earlier and trying to mimic the behaviour of
isLegalAddressingMode as closely as possible.

Differential Revision:  https://reviews.llvm.org/D37277
------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@315663 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tstellar committed Oct 13, 2017
1 parent cbc2c76 commit 0779919
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {

auto GTI = gep_type_begin(PointeeType, Operands);
Type *TargetType;

// Handle the case where the GEP instruction has a single operand,
// the basis, therefore TargetType is a nullptr.
if (Operands.empty())
return !BaseGV ? TTI::TCC_Free : TTI::TCC_Basic;

for (auto I = Operands.begin(); I != Operands.end(); ++I, ++GTI) {
TargetType = GTI.getIndexedType();
// We assume that the cost of Scalar GEP with constant index and the
Expand Down
28 changes: 28 additions & 0 deletions test/Transforms/SimplifyCFG/gepcost.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -simplifycfg | FileCheck %s

target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "thumbv7m-none--eabi"

@glob = external unnamed_addr constant [16 x i8]

define void @f() {
; CHECK-LABEL: @f(
; CHECK-NEXT: entr:
; CHECK-NEXT: br i1 undef, label [[NEXT:%.*]], label [[EXIT:%.*]]
; CHECK: next:
; CHECK-NEXT: [[PAT:%.*]] = getelementptr [16 x i8], [16 x i8]* @glob
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entr:
br i1 undef, label %next, label %exit

next:
%pat = getelementptr [16 x i8], [16 x i8]* @glob
br label %exit

exit:
ret void
}

0 comments on commit 0779919

Please sign in to comment.