Skip to content

Commit 4d11f51

Browse files
committed
Fix computeKnownBits for ARMISD::CMOV (rust-lang/llvm#67)
1 parent e6b944d commit 4d11f51

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

llvm.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Name: llvm
99
Version: 4.0.0
10-
Release: 2%{?dist}
10+
Release: 3%{?dist}
1111
Summary: The Low Level Virtual Machine
1212

1313
License: NCSA
@@ -17,6 +17,7 @@ Source0: http://llvm.org/releases/%{version}/%{name}-%{version}.src.tar.xz
1717
# recognize s390 as SystemZ when configuring build
1818
Patch0: llvm-3.7.1-cmake-s390.patch
1919
Patch1: 0001-CMake-Fix-pthread-handling-for-out-of-tree-builds.patch
20+
Patch2: rust-lang-llvm-pr67.patch
2021

2122
BuildRequires: cmake
2223
BuildRequires: zlib-devel
@@ -194,6 +195,9 @@ fi
194195
%{_libdir}/*.a
195196

196197
%changelog
198+
* Tue Apr 18 2017 Josh Stone <[email protected]> - 4.0.0-3
199+
- Fix computeKnownBits for ARMISD::CMOV (rust-lang/llvm#67)
200+
197201
* Mon Apr 03 2017 Tom Stellard <[email protected]> - 4.0.0-2
198202
- Simplify spec with rpm macros.
199203

rust-lang-llvm-pr67.patch

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From a6fa10c14649c18d299cddf3e823b032460cb6f5 Mon Sep 17 00:00:00 2001
2+
From: Pirama Arumuga Nainar <[email protected]>
3+
Date: Thu, 23 Mar 2017 16:47:47 +0000
4+
Subject: [PATCH] Fix computeKnownBits for ARMISD::CMOV
5+
6+
Summary:
7+
The true and false operands for the CMOV are operands 0 and 1.
8+
ARMISelLowering.cpp::computeKnownBits was looking at operands 1 and 2
9+
instead. This can cause CMOV instructions to be incorrectly folded into
10+
BFI if value set by the CMOV is another CMOV, whose known bits are
11+
computed incorrectly.
12+
13+
This patch fixes the issue and adds a test case.
14+
15+
Reviewers: kristof.beyls, jmolloy
16+
17+
Subscribers: llvm-commits, aemerson, srhines, rengolin
18+
19+
Differential Revision: https://reviews.llvm.org/D31265
20+
21+
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298624 91177308-0d34-0410-b5e6-96231b3b80d8
22+
---
23+
lib/Target/ARM/ARMISelLowering.cpp | 4 ++--
24+
test/CodeGen/ARM/no-cmov2bfi.ll | 19 +++++++++++++++++++
25+
2 files changed, 21 insertions(+), 2 deletions(-)
26+
create mode 100644 test/CodeGen/ARM/no-cmov2bfi.ll
27+
28+
diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp
29+
index 4a227a3cd7b1..cf98e60c0657 100644
30+
--- a/lib/Target/ARM/ARMISelLowering.cpp
31+
+++ b/lib/Target/ARM/ARMISelLowering.cpp
32+
@@ -10806,8 +10806,8 @@ static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero,
33+
if (Op.getOpcode() == ARMISD::CMOV) {
34+
APInt KZ2(KnownZero.getBitWidth(), 0);
35+
APInt KO2(KnownOne.getBitWidth(), 0);
36+
- computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne);
37+
- computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2);
38+
+ computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne);
39+
+ computeKnownBits(DAG, Op.getOperand(1), KZ2, KO2);
40+
41+
KnownZero &= KZ2;
42+
KnownOne &= KO2;
43+
diff --git a/test/CodeGen/ARM/no-cmov2bfi.ll b/test/CodeGen/ARM/no-cmov2bfi.ll
44+
new file mode 100644
45+
index 000000000000..c8b512048905
46+
--- /dev/null
47+
+++ b/test/CodeGen/ARM/no-cmov2bfi.ll
48+
@@ -0,0 +1,19 @@
49+
+; RUN: llc < %s -mtriple=thumbv7 | FileCheck --check-prefix=CHECK-NOBFI %s
50+
+
51+
+declare zeroext i1 @dummy()
52+
+
53+
+define i8 @test(i8 %a1, i1 %c) {
54+
+; CHECK-NOBFI-NOT: bfi
55+
+; CHECK-NOBFI: bl dummy
56+
+; CHECK-NOBFI: cmp r0, #0
57+
+; CHECK-NOBFI: it ne
58+
+; CHECK-NOBFI: orrne [[REG:r[0-9]+]], [[REG]], #8
59+
+; CHECK-NOBFI: mov r0, [[REG]]
60+
+
61+
+ %1 = and i8 %a1, -9
62+
+ %2 = select i1 %c, i8 %1, i8 %a1
63+
+ %3 = tail call zeroext i1 @dummy()
64+
+ %4 = or i8 %2, 8
65+
+ %ret = select i1 %3, i8 %4, i8 %2
66+
+ ret i8 %ret
67+
+}
68+
--
69+
2.9.3
70+

0 commit comments

Comments
 (0)