From 8f9c492c21902b0be5f1dce327b069d4b50b3e02 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 1 Oct 2024 00:04:11 +0700 Subject: [PATCH 1/2] [SPARC] Fix bugpoint regression from UpgradeDataLayoutString change It turns out that we cannot rely on the presence of `i64:64` as an "anchor" when adding the `-i128:128` string due to tools that generate custom datalayout strings (e.g bugpoint, among other things). Revert to the generic regex matcher to make sure that we can still add the i128 string in all other cases. This fixes the regression introduced in https://github.com/llvm/llvm-project/pull/106951. --- llvm/lib/IR/AutoUpgrade.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 6f833acd6dbc0..76c8a6db53346 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5519,12 +5519,12 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) { if (T.isSPARC()) { // Add "-i128:128" - std::string I64 = "-i64:64"; std::string I128 = "-i128:128"; if (!StringRef(Res).contains(I128)) { - size_t Pos = Res.find(I64); - assert(Pos != size_t(-1) && "no i64 data layout found!"); - Res.insert(Pos + I64.size(), I128); + SmallVector Groups; + Regex R("^([Ee](-[mpi][^-]*)*)((-[^mpi][^-]*)*)$"); + if (R.match(Res, &Groups)) + Res = (Groups[1] + I128 + Groups[3]).str(); } return Res; } From d86ada54a4ef7dd04e76069953d87814b0146e9e Mon Sep 17 00:00:00 2001 From: Koakuma Date: Wed, 2 Oct 2024 09:24:32 +0700 Subject: [PATCH 2/2] Take out the assert; do conditional insert instead --- llvm/lib/IR/AutoUpgrade.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 76c8a6db53346..d3e274f4e623d 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5519,12 +5519,12 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) { if (T.isSPARC()) { // Add "-i128:128" + std::string I64 = "-i64:64"; std::string I128 = "-i128:128"; if (!StringRef(Res).contains(I128)) { - SmallVector Groups; - Regex R("^([Ee](-[mpi][^-]*)*)((-[^mpi][^-]*)*)$"); - if (R.match(Res, &Groups)) - Res = (Groups[1] + I128 + Groups[3]).str(); + size_t Pos = Res.find(I64); + if (Pos != size_t(-1)) + Res.insert(Pos + I64.size(), I128); } return Res; }