From 832fef859a1fabc77d8dfc115d696b720438db4e Mon Sep 17 00:00:00 2001 From: Zoltán Böszörményi Date: Sat, 13 Feb 2021 00:19:53 -0500 Subject: llvm-project-source: Add a patch to fix LLVM bug 48921 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch was taken from https://bugs.llvm.org/show_bug.cgi?id=48921 Unfortunately, LLVM 11 is already closed so the patch was only accepted into LLVM 12. Also reported at https://gitlab.freedesktop.org/mesa/mesa/-/issues/4107 Signed-off-by: Zoltán Böszörményi --- .../clang/clang/D95527_against_11.x.patch | 85 ++++++++++++++++++++++ recipes-devtools/clang/common.inc | 1 + 2 files changed, 86 insertions(+) create mode 100644 recipes-devtools/clang/clang/D95527_against_11.x.patch diff --git a/recipes-devtools/clang/clang/D95527_against_11.x.patch b/recipes-devtools/clang/clang/D95527_against_11.x.patch new file mode 100644 index 0000000..f96f732 --- /dev/null +++ b/recipes-devtools/clang/clang/D95527_against_11.x.patch @@ -0,0 +1,85 @@ +commit b08a140a8fe8d0b0d16a93042b4952d6e34ab913 +Author: Piotr Sobczak +Date: Wed Jan 27 16:02:49 2021 +0100 + + [AMDGPU] Avoid an illegal operand in si-shrink-instructions + + Before the patch it was possible to trigger a constant bus + violation when folding immediates into a shrunk instruction. + + The patch adds a check to enforce the legality of the new operand. + + Differential Revision: https://reviews.llvm.org/D95527 + +diff --git a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp +index 9c6833a7dab6..6c1b16eddc84 100644 +--- a/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp ++++ b/llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp +@@ -84,21 +84,23 @@ static bool foldImmediates(MachineInstr &MI, const SIInstrInfo *TII, + MachineOperand &MovSrc = Def->getOperand(1); + bool ConstantFolded = false; + +- if (MovSrc.isImm() && (isInt<32>(MovSrc.getImm()) || +- isUInt<32>(MovSrc.getImm()))) { +- // It's possible to have only one component of a super-reg defined by +- // a single mov, so we need to clear any subregister flag. +- Src0.setSubReg(0); +- Src0.ChangeToImmediate(MovSrc.getImm()); +- ConstantFolded = true; +- } else if (MovSrc.isFI()) { +- Src0.setSubReg(0); +- Src0.ChangeToFrameIndex(MovSrc.getIndex()); +- ConstantFolded = true; +- } else if (MovSrc.isGlobal()) { +- Src0.ChangeToGA(MovSrc.getGlobal(), MovSrc.getOffset(), +- MovSrc.getTargetFlags()); +- ConstantFolded = true; ++ if (TII->isOperandLegal(MI, Src0Idx, &MovSrc)) { ++ if (MovSrc.isImm() && ++ (isInt<32>(MovSrc.getImm()) || isUInt<32>(MovSrc.getImm()))) { ++ // It's possible to have only one component of a super-reg defined ++ // by a single mov, so we need to clear any subregister flag. ++ Src0.setSubReg(0); ++ Src0.ChangeToImmediate(MovSrc.getImm()); ++ ConstantFolded = true; ++ } else if (MovSrc.isFI()) { ++ Src0.setSubReg(0); ++ Src0.ChangeToFrameIndex(MovSrc.getIndex()); ++ ConstantFolded = true; ++ } else if (MovSrc.isGlobal()) { ++ Src0.ChangeToGA(MovSrc.getGlobal(), MovSrc.getOffset(), ++ MovSrc.getTargetFlags()); ++ ConstantFolded = true; ++ } + } + + if (ConstantFolded) { +diff --git a/llvm/test/CodeGen/AMDGPU/shrink-instructions-illegal-fold.mir b/llvm/test/CodeGen/AMDGPU/shrink-instructions-illegal-fold.mir +new file mode 100644 +index 000000000000..7889f437facf +--- /dev/null ++++ b/llvm/test/CodeGen/AMDGPU/shrink-instructions-illegal-fold.mir +@@ -0,0 +1,23 @@ ++# RUN: llc -march=amdgcn -mcpu=gfx900 -run-pass=si-shrink-instructions --verify-machineinstrs %s -o - | FileCheck %s ++ ++# Make sure immediate folding into V_CNDMASK respects constant bus restrictions. ++--- ++ ++name: shrink_cndmask_illegal_imm_folding ++tracksRegLiveness: true ++body: | ++ bb.0: ++ liveins: $vgpr0, $vgpr1 ++ ; CHECK-LABEL: name: shrink_cndmask_illegal_imm_folding ++ ; CHECK: [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0 ++ ; CHECK: [[MOV:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 32768, implicit $exec ++ ; CHECK: V_CMP_EQ_U32_e32 0, [[COPY]], implicit-def $vcc, implicit $exec ++ ; CHECK: V_CNDMASK_B32_e32 [[MOV]], killed [[COPY]], implicit $vcc, implicit $exec ++ ++ %0:vgpr_32 = COPY $vgpr0 ++ %1:vgpr_32 = V_MOV_B32_e32 32768, implicit $exec ++ V_CMP_EQ_U32_e32 0, %0:vgpr_32, implicit-def $vcc, implicit $exec ++ %2:vgpr_32 = V_CNDMASK_B32_e64 0, %1:vgpr_32, 0, killed %0:vgpr_32, $vcc, implicit $exec ++ S_NOP 0 ++ ++... diff --git a/recipes-devtools/clang/common.inc b/recipes-devtools/clang/common.inc index 4709d28..8989904 100644 --- a/recipes-devtools/clang/common.inc +++ b/recipes-devtools/clang/common.inc @@ -35,6 +35,7 @@ SRC_URI = "\ file://0025-libcxx-Define-__NR_futex-to-be-__NR_futex_time64-on-.patch \ file://0026-clang-Use-python3-in-python-scripts.patch \ file://0027-For-x86_64-set-Yocto-based-GCC-install-search-path.patch \ + file://D95527_against_11.x.patch \ " # Fallback to no-PIE if not set -- cgit v1.2.3-54-g00ecf