tstellar / rpms / llvm

Forked from rpms/llvm 5 years ago
Clone
4d11f51
From a6fa10c14649c18d299cddf3e823b032460cb6f5 Mon Sep 17 00:00:00 2001
4d11f51
From: Pirama Arumuga Nainar <pirama@google.com>
4d11f51
Date: Thu, 23 Mar 2017 16:47:47 +0000
4d11f51
Subject: [PATCH] Fix computeKnownBits for ARMISD::CMOV
4d11f51
4d11f51
Summary:
4d11f51
The true and false operands for the CMOV are operands 0 and 1.
4d11f51
ARMISelLowering.cpp::computeKnownBits was looking at operands 1 and 2
4d11f51
instead.  This can cause CMOV instructions to be incorrectly folded into
4d11f51
BFI if value set by the CMOV is another CMOV, whose known bits are
4d11f51
computed incorrectly.
4d11f51
4d11f51
This patch fixes the issue and adds a test case.
4d11f51
4d11f51
Reviewers: kristof.beyls, jmolloy
4d11f51
4d11f51
Subscribers: llvm-commits, aemerson, srhines, rengolin
4d11f51
4d11f51
Differential Revision: https://reviews.llvm.org/D31265
4d11f51
4d11f51
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298624 91177308-0d34-0410-b5e6-96231b3b80d8
4d11f51
---
4d11f51
 lib/Target/ARM/ARMISelLowering.cpp |  4 ++--
4d11f51
 test/CodeGen/ARM/no-cmov2bfi.ll    | 19 +++++++++++++++++++
4d11f51
 2 files changed, 21 insertions(+), 2 deletions(-)
4d11f51
 create mode 100644 test/CodeGen/ARM/no-cmov2bfi.ll
4d11f51
4d11f51
diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp
4d11f51
index 4a227a3cd7b1..cf98e60c0657 100644
4d11f51
--- a/lib/Target/ARM/ARMISelLowering.cpp
4d11f51
+++ b/lib/Target/ARM/ARMISelLowering.cpp
4d11f51
@@ -10806,8 +10806,8 @@ static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero,
4d11f51
   if (Op.getOpcode() == ARMISD::CMOV) {
4d11f51
     APInt KZ2(KnownZero.getBitWidth(), 0);
4d11f51
     APInt KO2(KnownOne.getBitWidth(), 0);
4d11f51
-    computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne);
4d11f51
-    computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2);
4d11f51
+    computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne);
4d11f51
+    computeKnownBits(DAG, Op.getOperand(1), KZ2, KO2);
4d11f51
 
4d11f51
     KnownZero &= KZ2;
4d11f51
     KnownOne &= KO2;
4d11f51
diff --git a/test/CodeGen/ARM/no-cmov2bfi.ll b/test/CodeGen/ARM/no-cmov2bfi.ll
4d11f51
new file mode 100644
4d11f51
index 000000000000..c8b512048905
4d11f51
--- /dev/null
4d11f51
+++ b/test/CodeGen/ARM/no-cmov2bfi.ll
4d11f51
@@ -0,0 +1,19 @@
4d11f51
+; RUN: llc < %s -mtriple=thumbv7 | FileCheck --check-prefix=CHECK-NOBFI %s
4d11f51
+
4d11f51
+declare zeroext i1 @dummy()
4d11f51
+
4d11f51
+define i8 @test(i8 %a1, i1 %c) {
4d11f51
+; CHECK-NOBFI-NOT: bfi
4d11f51
+; CHECK-NOBFI: bl      dummy
4d11f51
+; CHECK-NOBFI: cmp     r0, #0
4d11f51
+; CHECK-NOBFI: it      ne
4d11f51
+; CHECK-NOBFI: orrne   [[REG:r[0-9]+]], [[REG]], #8
4d11f51
+; CHECK-NOBFI: mov     r0, [[REG]]
4d11f51
+
4d11f51
+  %1 = and i8 %a1, -9
4d11f51
+  %2 = select i1 %c, i8 %1, i8 %a1
4d11f51
+  %3 = tail call zeroext i1 @dummy()
4d11f51
+  %4 = or i8 %2, 8
4d11f51
+  %ret = select i1 %3, i8 %4, i8 %2
4d11f51
+  ret i8 %ret
4d11f51
+}
4d11f51
-- 
4d11f51
2.9.3
4d11f51