|
| 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