Skip to content

Commit 9367f08

Browse files
pirama-arumuga-nainarTimNN
authored andcommitted
[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 f639ecc commit 9367f08

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
@@ -11325,8 +11325,8 @@ static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero,
1132511325
if (Op.getOpcode() == ARMISD::CMOV) {
1132611326
APInt KZ2(KnownZero.getBitWidth(), 0);
1132711327
APInt KO2(KnownOne.getBitWidth(), 0);
11328-
computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne);
11329-
computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2);
11328+
computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne);
11329+
computeKnownBits(DAG, Op.getOperand(1), KZ2, KO2);
1133011330

1133111331
KnownZero &= KZ2;
1133211332
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)