From c11e2b94700e98606150db233e53b220431a5be2 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 22 Aug 2018 20:13:45 +0000 Subject: [ARM] Handle all-ones mask explicitly in targetShrinkDemandedConstant. This avoids a potential infinite loop setting and unsetting bits in the mask. Reduced from a failure on the polly-aosp bot. Differential Revision: https://reviews.llvm.org/D51066 llvm-svn: 340446 --- llvm/lib/Target/ARM/ARMISelLowering.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Target/ARM') diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index a0b612ff3c9..738f8234e4a 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -13647,14 +13647,21 @@ ARMTargetLowering::targetShrinkDemandedConstant(SDValue Op, unsigned Mask = C->getZExtValue(); - // If mask is zero, nothing to do. - if (!Mask) - return false; - unsigned Demanded = DemandedAPInt.getZExtValue(); unsigned ShrunkMask = Mask & Demanded; unsigned ExpandedMask = Mask | ~Demanded; + // If the mask is all zeros, let the target-independent code replace the + // result with zero. + if (ShrunkMask == 0) + return false; + + // If the mask is all ones, erase the AND. (Currently, the target-independent + // code won't do this, so we have to do it explicitly to avoid an infinite + // loop in obscure cases.) + if (ExpandedMask == ~0U) + return TLO.CombineTo(Op, Op.getOperand(0)); + auto IsLegalMask = [ShrunkMask, ExpandedMask](unsigned Mask) -> bool { return (ShrunkMask & Mask) == ShrunkMask && (~ExpandedMask & Mask) == 0; }; -- cgit v1.2.3