[PATCH] D156379: [SystemZ] Avoid type legalization on structs

Josh Stone via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 15:08:50 PDT 2023


cuviper created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
cuviper requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156379

Files:
  llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
  llvm/test/Analysis/CostModel/SystemZ/struct-cost-crash.ll


Index: llvm/test/Analysis/CostModel/SystemZ/struct-cost-crash.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/CostModel/SystemZ/struct-cost-crash.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output < %s | FileCheck %s
+;
+; Check that SystemZTTIImpl::getMemoryOpCost doesn't try to legalize structs,
+; which was failing llvm_unreachable in MVT::getVT.
+
+target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
+target triple = "s390x-unknown-linux-gnu"
+
+declare { i64, i32 } @bar()
+
+define i8 @foo() {
+; CHECK-LABEL: 'foo'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %1
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %2 = call { i64, i32 } @bar()
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 4 for instruction: store { i64, i32 } %2, ptr inttoptr (i64 16 to ptr), align 16
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: br label %1
+;
+  br label %1
+
+1:                                                ; preds = %1, %0
+  %2 = call { i64, i32 } @bar()
+  store { i64, i32 } %2, ptr inttoptr (i64 16 to ptr), align 16
+  br label %1
+}
Index: llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
===================================================================
--- llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
+++ llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
@@ -1152,6 +1152,11 @@
     }
   }
 
+  // Type legalization (via getNumberOfParts) can't handle structs
+  if (TLI->getValueType(DL, Src, true) == MVT::Other)
+    return BaseT::getMemoryOpCost(Opcode, Src, Alignment, AddressSpace,
+                                  CostKind);
+
   unsigned NumOps =
     (Src->isVectorTy() ? getNumVectorRegs(Src) : getNumberOfParts(Src));
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156379.544537.patch
Type: text/x-patch
Size: 1991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/a6de2749/attachment.bin>


More information about the llvm-commits mailing list