From 52a6f59d41086b05b11b2ce86946a22f1dc5c5b4 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Mon, 27 Oct 2014 19:58:36 +0000 Subject: [PATCH] [FastISel][AArch64] Emit immediate version of icmp (subs) for null pointer check. This is a minor change to use the immediate version when the operand is a null value. This should get rid of an unnecessary 'mov' instruction in debug builds and align the code more with the one generated by SelectionDAG. This fixes rdar://problem/18785125. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220713 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64FastISel.cpp | 8 ++++++-- test/CodeGen/AArch64/arm64-fast-isel-icmp.ll | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/Target/AArch64/AArch64FastISel.cpp b/lib/Target/AArch64/AArch64FastISel.cpp index 5527213c89d..01b2dee2612 100644 --- a/lib/Target/AArch64/AArch64FastISel.cpp +++ b/lib/Target/AArch64/AArch64FastISel.cpp @@ -1084,7 +1084,7 @@ unsigned AArch64FastISel::emitAddSub(bool UseAdd, MVT RetVT, const Value *LHS, RetVT.SimpleTy = std::max(RetVT.SimpleTy, MVT::i32); // Canonicalize immediates to the RHS first. - if (UseAdd && isa(LHS) && !isa(RHS)) + if (UseAdd && isa(LHS) && !isa(RHS)) std::swap(LHS, RHS); // Canonicalize mul by power of 2 to the RHS. @@ -1118,7 +1118,11 @@ unsigned AArch64FastISel::emitAddSub(bool UseAdd, MVT RetVT, const Value *LHS, else ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, Imm, SetFlags, WantResult); - } + } else if (const auto *C = dyn_cast(RHS)) + if (C->isNullValue()) + ResultReg = emitAddSub_ri(UseAdd, RetVT, LHSReg, LHSIsKill, 0, SetFlags, + WantResult); + if (ResultReg) return ResultReg; diff --git a/test/CodeGen/AArch64/arm64-fast-isel-icmp.ll b/test/CodeGen/AArch64/arm64-fast-isel-icmp.ll index 2d60783cd1c..245c70e8905 100644 --- a/test/CodeGen/AArch64/arm64-fast-isel-icmp.ll +++ b/test/CodeGen/AArch64/arm64-fast-isel-icmp.ll @@ -40,6 +40,26 @@ entry: ret i32 %conv } +define i32 @icmp_eq_ptr(i8* %a) { +entry: +; CHECK-LABEL: icmp_eq_ptr +; CHECK: cmp x0, #0 +; CHECK-NEXT: cset {{.+}}, eq + %cmp = icmp eq i8* %a, null + %conv = zext i1 %cmp to i32 + ret i32 %conv +} + +define i32 @icmp_ne_ptr(i8* %a) { +entry: +; CHECK-LABEL: icmp_ne_ptr +; CHECK: cmp x0, #0 +; CHECK-NEXT: cset {{.+}}, ne + %cmp = icmp ne i8* %a, null + %conv = zext i1 %cmp to i32 + ret i32 %conv +} + define i32 @icmp_ugt(i32 %a, i32 %b) nounwind ssp { entry: ; CHECK-LABEL: icmp_ugt