From 61639fb856c1222bea3fca2c92eba17ec67e94ae Mon Sep 17 00:00:00 2001 From: James Molloy Date: Mon, 16 Nov 2015 10:49:25 +0000 Subject: [PATCH] Properly check if a CMPZ node is in fact comparing against zero This was left implicit and never ever checked, which means we could have a CMPZ against some non-zero value and we were carrying on with BFI conversion regardless. Caught by Oliver Stannard using csmith; regression test added. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253195 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMISelLowering.cpp | 6 ++++++ test/CodeGen/ARM/bfi.ll | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index 51f8d562fe1..3c99675a473 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -10398,6 +10398,12 @@ SDValue ARMTargetLowering::PerformCMOVToBFICombine(SDNode *CMOV, SelectionDAG &D auto CC = CCNode->getAPIntValue().getLimitedValue(); SDValue CmpZ = CMOV->getOperand(4); + // The compare must be against zero. + SDValue Zero = CmpZ->getOperand(1); + if (!isa(Zero.getNode()) || + !cast(Zero.getNode())->isNullValue()) + return SDValue(); + assert(CmpZ->getOpcode() == ARMISD::CMPZ); SDValue And = CmpZ->getOperand(0); if (And->getOpcode() != ISD::AND) diff --git a/test/CodeGen/ARM/bfi.ll b/test/CodeGen/ARM/bfi.ll index 39bcbf2cfec..893fef3add7 100644 --- a/test/CodeGen/ARM/bfi.ll +++ b/test/CodeGen/ARM/bfi.ll @@ -158,3 +158,14 @@ define i32 @f12(i32 %x, i32 %y) { %sel = select i1 %cmp, i32 %y2, i32 %or ret i32 %sel } + +define i32 @f13(i32 %x, i32 %y) { +; CHECK-LABEL: f13: +; CHECK-NOT: bfi + %y2 = and i32 %y, 4294967040 ; 0xFFFFFF00 + %and = and i32 %x, 4 + %or = or i32 %y2, 16 + %cmp = icmp eq i32 %and, 42 ; Not comparing against zero! + %sel = select i1 %cmp, i32 %y2, i32 %or + ret i32 %sel +} -- 2.11.0