Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 9502e5b

Browse files
author
James Molloy
committed
Revert "[Thumb] Teach ISel how to lower compares of AND bitmasks efficiently"
This reverts commit r281323. It caused chromium test failures and a selfhost failure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281451 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 76c5395 commit 9502e5b

9 files changed

+26
-231
lines changed

lib/Target/ARM/ARMBaseInstrInfo.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -2528,11 +2528,7 @@ bool ARMBaseInstrInfo::optimizeCompareInstr(
25282528
case ARM::EORrr:
25292529
case ARM::EORri:
25302530
case ARM::t2EORrr:
2531-
case ARM::t2EORri:
2532-
case ARM::t2LSRri:
2533-
case ARM::t2LSRrr:
2534-
case ARM::t2LSLri:
2535-
case ARM::t2LSLrr: {
2531+
case ARM::t2EORri: {
25362532
// Scan forward for the use of CPSR
25372533
// When checking against MI: if it's a conditional code that requires
25382534
// checking of the V bit or C bit, then this is not safe to do.

lib/Target/ARM/ARMISelDAGToDAG.cpp

+4-133
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ class ARMDAGToDAGISel : public SelectionDAGISel {
244244
bool tryInlineAsm(SDNode *N);
245245

246246
void SelectConcatVector(SDNode *N);
247-
void SelectCMPZ(SDNode *N, bool &SwitchEQNEToPLMI);
248-
247+
249248
bool trySMLAWSMULW(SDNode *N);
250249

251250
void SelectCMP_SWAP(SDNode *N);
@@ -2694,83 +2693,6 @@ void ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
26942693
ReplaceNode(N, createDRegPairNode(VT, N->getOperand(0), N->getOperand(1)));
26952694
}
26962695

2697-
static Optional<std::pair<unsigned, unsigned>>
2698-
getContiguousRangeOfSetBits(const APInt &A) {
2699-
unsigned FirstOne = A.getBitWidth() - A.countLeadingZeros() - 1;
2700-
unsigned LastOne = A.countTrailingZeros();
2701-
if (A.countPopulation() != (FirstOne - LastOne + 1))
2702-
return Optional<std::pair<unsigned,unsigned>>();
2703-
return std::make_pair(FirstOne, LastOne);
2704-
}
2705-
2706-
void ARMDAGToDAGISel::SelectCMPZ(SDNode *N, bool &SwitchEQNEToPLMI) {
2707-
assert(N->getOpcode() == ARMISD::CMPZ);
2708-
SwitchEQNEToPLMI = false;
2709-
2710-
if (!Subtarget->isThumb())
2711-
// FIXME: Work out whether it is profitable to do this in A32 mode - LSL and
2712-
// LSR don't exist as standalone instructions - they need the barrel shifter.
2713-
return;
2714-
// select (cmpz (and X, C), #0) -> (LSLS X) or (LSRS X) or (LSRS (LSLS X))
2715-
SDValue And = N->getOperand(0);
2716-
SDValue Zero = N->getOperand(1);
2717-
if (!isa<ConstantSDNode>(Zero) || !cast<ConstantSDNode>(Zero)->isNullValue() ||
2718-
And->getOpcode() != ISD::AND)
2719-
return;
2720-
SDValue X = And.getOperand(0);
2721-
auto C = dyn_cast<ConstantSDNode>(And.getOperand(1));
2722-
2723-
if (!C || !X->hasOneUse())
2724-
return;
2725-
auto Range = getContiguousRangeOfSetBits(C->getAPIntValue());
2726-
if (!Range)
2727-
return;
2728-
2729-
// There are several ways to lower this:
2730-
SDNode *NewN;
2731-
SDLoc dl(N);
2732-
2733-
auto EmitShift = [&](unsigned Opc, SDValue Src, unsigned Imm) -> SDNode* {
2734-
if (Subtarget->isThumb2()) {
2735-
Opc = (Opc == ARM::tLSLri) ? ARM::t2LSLri : ARM::t2LSRri;
2736-
SDValue Ops[] = { Src, CurDAG->getTargetConstant(Imm, dl, MVT::i32),
2737-
getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32),
2738-
CurDAG->getRegister(0, MVT::i32) };
2739-
return CurDAG->getMachineNode(Opc, dl, MVT::i32, Ops);
2740-
} else {
2741-
SDValue Ops[] = {CurDAG->getRegister(ARM::CPSR, MVT::i32), Src,
2742-
CurDAG->getTargetConstant(Imm, dl, MVT::i32),
2743-
getAL(CurDAG, dl), CurDAG->getRegister(0, MVT::i32)};
2744-
return CurDAG->getMachineNode(Opc, dl, MVT::i32, Ops);
2745-
}
2746-
};
2747-
2748-
if (Range->second == 0) {
2749-
// 1. Mask includes the LSB -> Simply shift the top N bits off
2750-
NewN = EmitShift(ARM::tLSLri, X, 31 - Range->first);
2751-
ReplaceNode(And.getNode(), NewN);
2752-
} else if (Range->first == 31) {
2753-
// 2. Mask includes the MSB -> Simply shift the bottom N bits off
2754-
NewN = EmitShift(ARM::tLSRri, X, Range->second);
2755-
ReplaceNode(And.getNode(), NewN);
2756-
} else if (Range->first == Range->second) {
2757-
// 3. Only one bit is set. We can shift this into the sign bit and use a
2758-
// PL/MI comparison.
2759-
NewN = EmitShift(ARM::tLSLri, X, 31 - Range->first);
2760-
ReplaceNode(And.getNode(), NewN);
2761-
2762-
SwitchEQNEToPLMI = true;
2763-
} else if (!Subtarget->hasV6T2Ops()) {
2764-
// 4. Do a double shift to clear bottom and top bits, but only in
2765-
// thumb-1 mode as in thumb-2 we can use UBFX.
2766-
NewN = EmitShift(ARM::tLSLri, X, 31 - Range->first);
2767-
NewN = EmitShift(ARM::tLSRri, SDValue(NewN, 0),
2768-
Range->second + (31 - Range->first));
2769-
ReplaceNode(And.getNode(), NewN);
2770-
}
2771-
2772-
}
2773-
27742696
void ARMDAGToDAGISel::Select(SDNode *N) {
27752697
SDLoc dl(N);
27762698

@@ -2998,7 +2920,6 @@ void ARMDAGToDAGISel::Select(SDNode *N) {
29982920
return;
29992921
}
30002922
}
3001-
30022923
break;
30032924
}
30042925
case ARMISD::VMOVRRD:
@@ -3189,27 +3110,9 @@ void ARMDAGToDAGISel::Select(SDNode *N) {
31893110
assert(N2.getOpcode() == ISD::Constant);
31903111
assert(N3.getOpcode() == ISD::Register);
31913112

3192-
unsigned CC = (unsigned) cast<ConstantSDNode>(N2)->getZExtValue();
3193-
3194-
if (InFlag.getOpcode() == ARMISD::CMPZ) {
3195-
bool SwitchEQNEToPLMI;
3196-
SelectCMPZ(InFlag.getNode(), SwitchEQNEToPLMI);
3197-
InFlag = N->getOperand(4);
3198-
3199-
if (SwitchEQNEToPLMI) {
3200-
switch ((ARMCC::CondCodes)CC) {
3201-
default: llvm_unreachable("CMPZ must be either NE or EQ!");
3202-
case ARMCC::NE:
3203-
CC = (unsigned)ARMCC::MI;
3204-
break;
3205-
case ARMCC::EQ:
3206-
CC = (unsigned)ARMCC::PL;
3207-
break;
3208-
}
3209-
}
3210-
}
3211-
3212-
SDValue Tmp2 = CurDAG->getTargetConstant(CC, dl, MVT::i32);
3113+
SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
3114+
cast<ConstantSDNode>(N2)->getZExtValue()), dl,
3115+
MVT::i32);
32133116
SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
32143117
SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
32153118
MVT::Glue, Ops);
@@ -3264,38 +3167,6 @@ void ARMDAGToDAGISel::Select(SDNode *N) {
32643167
// Other cases are autogenerated.
32653168
break;
32663169
}
3267-
3268-
case ARMISD::CMOV: {
3269-
SDValue InFlag = N->getOperand(4);
3270-
3271-
if (InFlag.getOpcode() == ARMISD::CMPZ) {
3272-
bool SwitchEQNEToPLMI;
3273-
SelectCMPZ(InFlag.getNode(), SwitchEQNEToPLMI);
3274-
3275-
if (SwitchEQNEToPLMI) {
3276-
SDValue ARMcc = N->getOperand(2);
3277-
ARMCC::CondCodes CC =
3278-
(ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue();
3279-
3280-
switch (CC) {
3281-
default: llvm_unreachable("CMPZ must be either NE or EQ!");
3282-
case ARMCC::NE:
3283-
CC = ARMCC::MI;
3284-
break;
3285-
case ARMCC::EQ:
3286-
CC = ARMCC::PL;
3287-
break;
3288-
}
3289-
SDValue NewARMcc = CurDAG->getConstant((unsigned)CC, dl, MVT::i32);
3290-
SDValue Ops[] = {N->getOperand(0), N->getOperand(1), NewARMcc,
3291-
N->getOperand(3), N->getOperand(4)};
3292-
CurDAG->MorphNodeTo(N, ARMISD::CMOV, N->getVTList(), Ops);
3293-
}
3294-
3295-
}
3296-
// Other cases are autogenerated.
3297-
break;
3298-
}
32993170

33003171
case ARMISD::VZIP: {
33013172
unsigned Opc = 0;

test/CodeGen/ARM/and-cmpz.ll

-71
This file was deleted.

test/CodeGen/ARM/arm-and-tst-peephole.ll

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ tailrecurse: ; preds = %sw.bb, %entry
2828
; ARM: ands {{r[0-9]+}}, {{r[0-9]+}}, #3
2929
; ARM-NEXT: beq
3030

31-
; THUMB: lsls r[[R0:[0-9]+]], r{{.*}}, #30
31+
; THUMB: movs r[[R0:[0-9]+]], #3
32+
; THUMB-NEXT: ands r[[R0]], r
33+
; THUMB-NEXT: cmp r[[R0]], #0
3234
; THUMB-NEXT: beq
3335

34-
; T2: lsls r[[R0:[0-9]+]], r{{.*}}, #30
36+
; T2: ands {{r[0-9]+}}, {{r[0-9]+}}, #3
3537
; T2-NEXT: beq
3638

3739
%and = and i32 %0, 3
@@ -91,7 +93,7 @@ entry:
9193
%1 = load i8, i8* %0, align 1
9294
%2 = zext i8 %1 to i32
9395
; ARM: ands
94-
; THUMB: lsls
96+
; THUMB: ands
9597
; T2: ands
9698
; V8: ands
9799
; V8-NEXT: beq
@@ -148,9 +150,10 @@ define i32 @test_tst_assessment(i1 %lhs, i1 %rhs) {
148150
%rhs32 = zext i1 %rhs to i32
149151
%diff = sub nsw i32 %lhs32, %rhs32
150152
; ARM: tst r1, #1
151-
; THUMB: lsls r1, r1, #31
152-
; T2: lsls r1, r1, #31
153-
; V8: lsls r1, r1, #31
153+
; THUMB: movs [[RTMP:r[0-9]+]], #1
154+
; THUMB: tst r1, [[RTMP]]
155+
; T2: tst.w r1, #1
156+
; V8: tst.w r1, #1
154157
ret i32 %diff
155158
}
156159

test/CodeGen/ARM/arm-shrink-wrapping.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,12 @@ declare double @llvm.pow.f64(double, double)
638638
; during PEI with shrink-wrapping enable.
639639
; CHECK-LABEL: debug_info:
640640
;
641-
; ENABLE: {{tst r2, #1|lsls r1, r2, #31}}
641+
; ENABLE: tst{{(\.w)?}} r2, #1
642642
; ENABLE-NEXT: beq [[BB13:LBB[0-9_]+]]
643643
;
644644
; CHECK: push
645645
;
646-
; DISABLE: {{tst r2, #1|lsls r1, r2, #31}}
646+
; DISABLE: tst{{(\.w)?}} r2, #1
647647
; DISABLE-NEXT: beq [[BB13:LBB[0-9_]+]]
648648
;
649649
; CHECK: bl{{x?}} _pow

test/CodeGen/ARM/call-tc.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ if.end: ; preds = %entry
120120
br i1 %tobool2, label %if.end5, label %if.then3
121121

122122
if.then3: ; preds = %if.end
123-
; CHECKT2D: bmi.w _b
123+
; CHECKT2D: bne.w _b
124124
%call4 = tail call i32 @b(i32 %x) nounwind
125125
br label %return
126126

test/CodeGen/ARM/debug-info-branch-folding.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-
33
target triple = "thumbv7-apple-macosx10.6.7"
44

55
;CHECK: vadd.f32 q4, q8, q8
6-
;CHECK-NEXT: Ltmp
6+
;CHECK-NEXT: Ltmp1
77
;CHECK-NEXT: LBB0_1
88

99
;CHECK:@DEBUG_VALUE: x <- %Q4{{$}}

test/CodeGen/Thumb/thumb-shrink-wrapping.ll

+2-6
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,11 @@ define i1 @beq_to_bx(i32* %y, i32 %head) {
650650

651651
; CHECK: tst r3, r4
652652
; ENABLE-NEXT: pop {r4}
653-
; ENABLE-NEXT: mov r12, r{{.*}}
654-
; ENABLE-NEXT: pop {r0}
655-
; ENABLE-NEXT: mov lr, r0
656-
; ENABLE-NEXT: mov r0, r12
653+
; ENABLE-NEXT: pop {r3}
654+
; ENABLE-NEXT: mov lr, r3
657655
; CHECK-NEXT: beq [[EXIT_LABEL]]
658656

659657
; CHECK: str r1, [r2]
660-
; CHECK: str r3, [r2]
661658
; CHECK-NEXT: movs r0, #0
662659
; CHECK-NEXT: [[EXIT_LABEL]]: @ %cleanup
663660
; ENABLE-NEXT: bx lr
@@ -678,7 +675,6 @@ if.end:
678675

679676
if.end4:
680677
store i32 %head, i32* %y, align 4
681-
store volatile i32 %z, i32* %y, align 4
682678
br label %cleanup
683679

684680
cleanup:

test/CodeGen/Thumb2/float-ops.ll

+6-6
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ define i64 @bitcast_d_to_i(double %a) {
259259

260260
define float @select_f(float %a, float %b, i1 %c) {
261261
; CHECK-LABEL: select_f:
262-
; NONE: lsls r2, r2, #31
262+
; NONE: tst.w r2, #1
263263
; NONE: moveq r0, r1
264-
; HARD: lsls r0, r0, #31
264+
; HARD: tst.w r0, #1
265265
; VFP4-ALL: vmovne.f32 s1, s0
266266
; VFP4-ALL: vmov.f32 s0, s1
267267
; FP-ARMv8: vseleq.f32 s0, s1, s0
@@ -271,18 +271,18 @@ define float @select_f(float %a, float %b, i1 %c) {
271271

272272
define double @select_d(double %a, double %b, i1 %c) {
273273
; CHECK-LABEL: select_d:
274-
; NONE: ldr{{(.w)?}} [[REG:r[0-9]+]], [sp]
275-
; NONE: lsls{{(.w)?}} [[REG]], [[REG]], #31
274+
; NONE: ldr.w [[REG:r[0-9]+]], [sp]
275+
; NONE: ands [[REG]], [[REG]], #1
276276
; NONE: moveq r0, r2
277277
; NONE: moveq r1, r3
278-
; SP: lsls r0, r0, #31
278+
; SP: ands r0, r0, #1
279279
; SP-DAG: vmov [[ALO:r[0-9]+]], [[AHI:r[0-9]+]], d0
280280
; SP-DAG: vmov [[BLO:r[0-9]+]], [[BHI:r[0-9]+]], d1
281281
; SP: itt ne
282282
; SP-DAG: movne [[BLO]], [[ALO]]
283283
; SP-DAG: movne [[BHI]], [[AHI]]
284284
; SP: vmov d0, [[BLO]], [[BHI]]
285-
; DP: lsls r0, r0, #31
285+
; DP: tst.w r0, #1
286286
; VFP4-DP: vmovne.f64 d1, d0
287287
; VFP4-DP: vmov.f64 d0, d1
288288
; FP-ARMV8: vseleq.f64 d0, d1, d0

0 commit comments

Comments
 (0)