Skip to content

Commit 7470d9a

Browse files
cuvipertru
authored andcommitted
[SystemZ] Avoid type legalization on structs
In SystemZTTIImpl::getMemoryOpCost, the call to getNumberOfParts will run type legalization, which can't handle structs. So before that, we check for an unknown value type and forward to BaseT, just like many other targets do in this situation. https://bugzilla.redhat.com/show_bug.cgi?id=2224885 Reviewed By: uweigand Differential Revision: https://reviews.llvm.org/D156379 (cherry picked from commit 85e4ee1)
1 parent efcacdb commit 7470d9a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,11 @@ InstructionCost SystemZTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
11521152
}
11531153
}
11541154

1155+
// Type legalization (via getNumberOfParts) can't handle structs
1156+
if (TLI->getValueType(DL, Src, true) == MVT::Other)
1157+
return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
1158+
CostKind);
1159+
11551160
unsigned NumOps =
11561161
(Src->isVectorTy() ? getNumVectorRegs(Src) : getNumberOfParts(Src));
11571162

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
2+
; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output < %s | FileCheck %s
3+
;
4+
; Check that SystemZTTIImpl::getMemoryOpCost doesn't try to legalize structs,
5+
; which was failing llvm_unreachable in MVT::getVT.
6+
7+
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
8+
target triple = "s390x-unknown-linux-gnu"
9+
10+
declare { i64, i32 } @bar()
11+
12+
define i8 @foo() {
13+
; CHECK-LABEL: 'foo'
14+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %1
15+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %2 = call { i64, i32 } @bar()
16+
; CHECK-NEXT: Cost Model: Found an estimated cost of 4 for instruction: store { i64, i32 } %2, ptr inttoptr (i64 16 to ptr), align 16
17+
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: br label %1
18+
;
19+
br label %1
20+
21+
1: ; preds = %1, %0
22+
%2 = call { i64, i32 } @bar()
23+
store { i64, i32 } %2, ptr inttoptr (i64 16 to ptr), align 16
24+
br label %1
25+
}

0 commit comments

Comments
 (0)