Skip to content

Commit 5a42474

Browse files
committed
Backport LLVM patches to fix AVX on i686
This fixes a bug in the patch that fixes #19976 causing encoding error on 32bit x86 and segfault when AVX/AVX2 is enabled. Ref LLVM bug report https://bugs.llvm.org//show_bug.cgi?id=29010 LLVM commit llvm-mirror/llvm@83260f2 Also ref where I saw this issue in #21849 (comment)
1 parent 063e8f1 commit 5a42474

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

deps/llvm.mk

+1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ $(eval $(call LLVM_PATCH,llvm-D28786-callclearance))
499499
$(eval $(call LLVM_PATCH,llvm-rL293230-icc17-cmake)) # Remove for 4.0
500500
$(eval $(call LLVM_PATCH,llvm-D32593))
501501
$(eval $(call LLVM_PATCH,llvm-D33179))
502+
$(eval $(call LLVM_PATCH,llvm-PR29010-i386-xmm)) # Remove for 4.0
502503
endif # LLVM_VER
503504

504505
ifeq ($(LLVM_VER),3.7.1)
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From 83260f239481dfb40d325cf35005c20eeb767b6c Mon Sep 17 00:00:00 2001
2+
From: Marina Yatsina <[email protected]>
3+
Date: Wed, 17 Aug 2016 19:07:40 +0000
4+
Subject: [PATCH] Fix for PR29010
5+
6+
This is a fix for https://llvm.org/bugs/show_bug.cgi?id=29010
7+
Root cause of the bug is that the register class of the machine instruction operand does not fully reflect if this registers that can be allocated.
8+
Both for i386 and x86_64 the operand's register class is VR128RegClass and thus contains xmm0-xmm15, though in i386 we can only use xmm0-xmm8.
9+
In order to get the actual allocable registers of the class we need to use RegisterClassInfo.
10+
11+
Differential Revision: https://reviews.llvm.org/D23613
12+
13+
14+
15+
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278954 91177308-0d34-0410-b5e6-96231b3b80d8
16+
---
17+
lib/CodeGen/ExecutionDepsFix.cpp | 6 +++++-
18+
test/CodeGen/X86/pr29010.ll | 12 ++++++++++++
19+
2 files changed, 17 insertions(+), 1 deletion(-)
20+
create mode 100644 test/CodeGen/X86/pr29010.ll
21+
22+
diff --git a/lib/CodeGen/ExecutionDepsFix.cpp b/lib/CodeGen/ExecutionDepsFix.cpp
23+
index 213dd58a31d..2f173f84d73 100644
24+
--- a/lib/CodeGen/ExecutionDepsFix.cpp
25+
+++ b/lib/CodeGen/ExecutionDepsFix.cpp
26+
@@ -26,6 +26,7 @@
27+
#include "llvm/CodeGen/LivePhysRegs.h"
28+
#include "llvm/CodeGen/MachineFunctionPass.h"
29+
#include "llvm/CodeGen/MachineRegisterInfo.h"
30+
+#include "llvm/CodeGen/RegisterClassInfo.h"
31+
#include "llvm/Support/Allocator.h"
32+
#include "llvm/Support/Debug.h"
33+
#include "llvm/Support/raw_ostream.h"
34+
@@ -137,6 +138,7 @@ class ExeDepsFix : public MachineFunctionPass {
35+
MachineFunction *MF;
36+
const TargetInstrInfo *TII;
37+
const TargetRegisterInfo *TRI;
38+
+ RegisterClassInfo RegClassInfo;
39+
std::vector<SmallVector<int, 1>> AliasMap;
40+
const unsigned NumRegs;
41+
LiveReg *LiveRegs;
42+
@@ -509,7 +511,8 @@ void ExeDepsFix::pickBestRegisterForUndef(MachineInstr *MI, unsigned OpIdx,
43+
// max clearance or clearance higher than Pref.
44+
unsigned MaxClearance = 0;
45+
unsigned MaxClearanceReg = OriginalReg;
46+
- for (auto Reg : OpRC->getRegisters()) {
47+
+ ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder(OpRC);
48+
+ for (auto Reg : Order) {
49+
assert(AliasMap[Reg].size() == 1 &&
50+
"Reg is expected to be mapped to a single index");
51+
int RCrx = *regIndices(Reg).begin();
52+
@@ -785,6 +788,7 @@ bool ExeDepsFix::runOnMachineFunction(MachineFunction &mf) {
53+
MF = &mf;
54+
TII = MF->getSubtarget().getInstrInfo();
55+
TRI = MF->getSubtarget().getRegisterInfo();
56+
+ RegClassInfo.runOnMachineFunction(mf);
57+
LiveRegs = nullptr;
58+
assert(NumRegs == RC->getNumRegs() && "Bad regclass");
59+
60+
diff --git a/test/CodeGen/X86/pr29010.ll b/test/CodeGen/X86/pr29010.ll
61+
new file mode 100644
62+
index 00000000000..a2d5ff69a35
63+
--- /dev/null
64+
+++ b/test/CodeGen/X86/pr29010.ll
65+
@@ -0,0 +1,12 @@
66+
+; RUN: llc < %s -mtriple=i386-linux -mattr=+avx | FileCheck %s
67+
+
68+
+; In i386 there are only 8 XMMs (xmm0-xmm7), make sure we we are not creating illegal XMM
69+
+define float @only_xmm0_7(i32 %arg) {
70+
+top:
71+
+ tail call void asm sideeffect "", "~{xmm0},~{xmm1},~{xmm2},~{xmm3},~{dirflag},~{fpsr},~{flags}"()
72+
+ tail call void asm sideeffect "", "~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{dirflag},~{fpsr},~{flags}"()
73+
+ %tmp1 = sitofp i32 %arg to float
74+
+ ret float %tmp1
75+
+;CHECK-LABEL:@only_xmm0_7
76+
+;CHECK: vcvtsi2ssl {{.*}}, {{%xmm[0-7]+}}, {{%xmm[0-7]+}}
77+
+}
78+
--
79+
2.13.0
80+

0 commit comments

Comments
 (0)