From: Weiming Zhao Date: Tue, 13 May 2014 00:40:58 +0000 (+0000) Subject: Folding into CSEL when there is ZEXT between SETCC and ADD X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0449d522a66512af6e7b999d46445c7f7e4b8536;p=oota-llvm.git Folding into CSEL when there is ZEXT between SETCC and ADD Normally, patterns like (add x, (setcc cc ...)) will be folded into (csel x, x+1, not cc). However, if there is a ZEXT after SETCC, they won't be folded. This patch recognizes the ZEXT and allows the generation of CSINC. This patch fixes bug 19680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208660 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/ARM64/ARM64ISelLowering.cpp b/lib/Target/ARM64/ARM64ISelLowering.cpp index 1d27e86e215..546343a0feb 100644 --- a/lib/Target/ARM64/ARM64ISelLowering.cpp +++ b/lib/Target/ARM64/ARM64ISelLowering.cpp @@ -6600,8 +6600,16 @@ static bool isSetCC(SDValue Op, SetCCInfoAndKind &SetCCInfo) { return TValue->isOne() && FValue->isNullValue(); } +// Returns true if Op is setcc or zext of setcc. +static bool isSetCCOrZExtSetCC(const SDValue& Op, SetCCInfoAndKind &Info) { + if (isSetCC(Op, Info)) + return true; + return ((Op.getOpcode() == ISD::ZERO_EXTEND) && + isSetCC(Op->getOperand(0), Info)); +} + // The folding we want to perform is: -// (add x, (setcc cc ...) ) +// (add x, [zext] (setcc cc ...) ) // --> // (csel x, (add x, 1), !cc ...) // @@ -6613,9 +6621,9 @@ static SDValue performSetccAddFolding(SDNode *Op, SelectionDAG &DAG) { SetCCInfoAndKind InfoAndKind; // If neither operand is a SET_CC, give up. - if (!isSetCC(LHS, InfoAndKind)) { + if (!isSetCCOrZExtSetCC(LHS, InfoAndKind)) { std::swap(LHS, RHS); - if (!isSetCC(LHS, InfoAndKind)) + if (!isSetCCOrZExtSetCC(LHS, InfoAndKind)) return SDValue(); } diff --git a/test/CodeGen/ARM64/csel.ll b/test/CodeGen/ARM64/csel.ll index 975056bfa2c..98eba30f119 100644 --- a/test/CodeGen/ARM64/csel.ll +++ b/test/CodeGen/ARM64/csel.ll @@ -217,3 +217,14 @@ entry: %. = select i1 %cmp, i64 1, i64 2 ret i64 %. } + +define i64 @foo19(i64 %a, i64 %b, i64 %c) { +entry: +; CHECK-LABEL: foo19: +; CHECK: cinc x0, x2 +; CHECK-NOT: add + %cmp = icmp ult i64 %a, %b + %inc = zext i1 %cmp to i64 + %inc.c = add i64 %inc, %c + ret i64 %inc.c +}