From: Juergen Ributzka Date: Thu, 6 Aug 2015 22:44:15 +0000 (+0000) Subject: [AArch64][FastISel] Always use AND before checking the branch flag. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=138cd6dae83ff8802cc9fd16fae4efb0a6a6ab11;p=oota-llvm.git [AArch64][FastISel] Always use AND before checking the branch flag. When we are not emitting the condition for the branch, because the condition is in another BB or SDAG did the selection for us, then we have to mask the flag in the register with AND. This is required when the condition comes from a truncate, because SDAG only truncates down to a legal size of i32. This fixes rdar://problem/22161062. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244291 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AArch64/AArch64FastISel.cpp b/lib/Target/AArch64/AArch64FastISel.cpp index 280e5fc2b50..ab24fe4454e 100644 --- a/lib/Target/AArch64/AArch64FastISel.cpp +++ b/lib/Target/AArch64/AArch64FastISel.cpp @@ -2413,7 +2413,11 @@ bool AArch64FastISel::selectBranch(const Instruction *I) { // Regardless, the compare has been done in the predecessor block, // and it left a value for us in a virtual register. Ergo, we test // the one-bit value left in the virtual register. - emitICmp_ri(MVT::i32, CondReg, CondRegIsKill, 0); + // + // FIXME: Optimize this with TBZW/TBZNW. + unsigned ANDReg = emitAnd_ri(MVT::i32, CondReg, CondRegIsKill, 1); + assert(ANDReg && "Unexpected AND instruction emission failure."); + emitICmp_ri(MVT::i32, ANDReg, /*IsKill=*/true, 0); if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { std::swap(TBB, FBB); diff --git a/test/CodeGen/AArch64/fast-isel-branch-cond-mask.ll b/test/CodeGen/AArch64/fast-isel-branch-cond-mask.ll new file mode 100644 index 00000000000..c018b2778b0 --- /dev/null +++ b/test/CodeGen/AArch64/fast-isel-branch-cond-mask.ll @@ -0,0 +1,20 @@ +; RUN: llc -mtriple=aarch64-apple-darwin -O0 -fast-isel -fast-isel-abort=0 -verify-machineinstrs < %s | FileCheck %s + +define void @test(i64 %a, i64 %b, i2* %c) { +; CHECK-LABEL: test +; CHECK: and [[REG1:w[0-9]+]], w8, #0x3 +; CHECK-NEXT: strb [[REG1]], {{\[}}x2{{\]}} +; CHECK: and [[REG2:w[0-9]+]], w8, #0x1 +; CHECK-NEXT: cmp [[REG2]], #0 + %1 = trunc i64 %a to i2 + %2 = trunc i64 %b to i1 +; Force fast-isel to fall back to SDAG. + store i2 %1, i2* %c, align 8 + br i1 %2, label %bb1, label %bb2 + +bb1: + ret void + +bb2: + ret void +}