[llvm] r253195 - Properly check if a CMPZ node is in fact comparing against zero
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 16 02:49:25 PST 2015
Author: jamesm
Date: Mon Nov 16 04:49:25 2015
New Revision: 253195
URL: http://llvm.org/viewvc/llvm-project?rev=253195&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
llvm/trunk/test/CodeGen/ARM/bfi.ll
Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=253195&r1=253194&r2=253195&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Mon Nov 16 04:49:25 2015
@@ -10398,6 +10398,12 @@ SDValue ARMTargetLowering::PerformCMOVTo
auto CC = CCNode->getAPIntValue().getLimitedValue();
SDValue CmpZ = CMOV->getOperand(4);
+ // The compare must be against zero.
+ SDValue Zero = CmpZ->getOperand(1);
+ if (!isa<ConstantSDNode>(Zero.getNode()) ||
+ !cast<ConstantSDNode>(Zero.getNode())->isNullValue())
+ return SDValue();
+
assert(CmpZ->getOpcode() == ARMISD::CMPZ);
SDValue And = CmpZ->getOperand(0);
if (And->getOpcode() != ISD::AND)
Modified: llvm/trunk/test/CodeGen/ARM/bfi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/bfi.ll?rev=253195&r1=253194&r2=253195&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/bfi.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/bfi.ll Mon Nov 16 04:49:25 2015
@@ -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
+}
More information about the llvm-commits
mailing list