Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit cdc303e

Browse files
[ARM] Fix computeKnownBits for ARMISD::CMOV
Summary: The true and false operands for the CMOV are operands 0 and 1. ARMISelLowering.cpp::computeKnownBits was looking at operands 1 and 2 instead. This can cause CMOV instructions to be incorrectly folded into BFI if value set by the CMOV is another CMOV, whose known bits are computed incorrectly. This patch fixes the issue and adds a test case. Reviewers: kristof.beyls, jmolloy Subscribers: llvm-commits, aemerson, srhines, rengolin Differential Revision: https://reviews.llvm.org/D31265 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298624 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 83cc1fc commit cdc303e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11695,8 +11695,8 @@ static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero,
1169511695
if (Op.getOpcode() == ARMISD::CMOV) {
1169611696
APInt KZ2(KnownZero.getBitWidth(), 0);
1169711697
APInt KO2(KnownOne.getBitWidth(), 0);
11698-
computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne);
11699-
computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2);
11698+
computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne);
11699+
computeKnownBits(DAG, Op.getOperand(1), KZ2, KO2);
1170011700

1170111701
KnownZero &= KZ2;
1170211702
KnownOne &= KO2;

test/CodeGen/ARM/no-cmov2bfi.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc < %s -mtriple=thumbv7 | FileCheck --check-prefix=CHECK-NOBFI %s
2+
3+
declare zeroext i1 @dummy()
4+
5+
define i8 @test(i8 %a1, i1 %c) {
6+
; CHECK-NOBFI-NOT: bfi
7+
; CHECK-NOBFI: bl dummy
8+
; CHECK-NOBFI: cmp r0, #0
9+
; CHECK-NOBFI: it ne
10+
; CHECK-NOBFI: orrne [[REG:r[0-9]+]], [[REG]], #8
11+
; CHECK-NOBFI: mov r0, [[REG]]
12+
13+
%1 = and i8 %a1, -9
14+
%2 = select i1 %c, i8 %1, i8 %a1
15+
%3 = tail call zeroext i1 @dummy()
16+
%4 = or i8 %2, 8
17+
%ret = select i1 %3, i8 %4, i8 %2
18+
ret i8 %ret
19+
}

0 commit comments

Comments
 (0)