Skip to content

Commit 74bace2

Browse files
committed
Revert "[AArch64] Improve codegen for shifted mask op"
This reverts commit b4e1466. This causes a crash while building the Linux kernel. See the original Phabricator review for a reduced C and LLVM IR reproducer.
1 parent 5d7fdf6 commit 74bace2

File tree

2 files changed

+6
-38
lines changed

2 files changed

+6
-38
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14442,23 +14442,15 @@ AArch64TargetLowering::isDesirableToCommuteWithShift(const SDNode *N,
1444214442
SDValue ShiftLHS = N->getOperand(0);
1444314443
EVT VT = N->getValueType(0);
1444414444

14445-
// If ShiftLHS is unsigned bit extraction: ((x >> C) & mask), then do not
14446-
// combine it with shift 'N' to let it be lowered to UBFX except:
14447-
// ((x >> C) & mask) << C.
14445+
// If ShiftLHS is unsigned bit extraction: ((x >> C) & mask), then do not combine
14446+
// it with shift 'N' to let it be lowered to UBFX.
1444814447
if (ShiftLHS.getOpcode() == ISD::AND && (VT == MVT::i32 || VT == MVT::i64) &&
1444914448
isa<ConstantSDNode>(ShiftLHS.getOperand(1))) {
1445014449
uint64_t TruncMask = ShiftLHS.getConstantOperandVal(1);
14451-
if (isMask_64(TruncMask)) {
14452-
SDValue AndLHS = ShiftLHS.getOperand(0);
14453-
if (AndLHS.getOpcode() == ISD::SRL) {
14454-
if (auto *SRLC = dyn_cast<ConstantSDNode>(AndLHS.getOperand(1))) {
14455-
if (N->getOpcode() == ISD::SHL)
14456-
if (auto *SHLC = dyn_cast<ConstantSDNode>(N->getOperand(1)))
14457-
return SRLC->getAPIntValue() == SHLC->getAPIntValue();
14458-
return false;
14459-
}
14460-
}
14461-
}
14450+
if (isMask_64(TruncMask) &&
14451+
ShiftLHS.getOperand(0).getOpcode() == ISD::SRL &&
14452+
isa<ConstantSDNode>(ShiftLHS.getOperand(0).getOperand(1)))
14453+
return false;
1446214454
}
1446314455
return true;
1446414456
}

llvm/test/CodeGen/AArch64/shift-logic.ll

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,3 @@ define i32 @lshr_or_extra_use(i32 %x, i32 %y, i32* %p) nounwind {
151151
%sh1 = lshr i32 %r, 7
152152
ret i32 %sh1
153153
}
154-
155-
define i64 @desirable_to_commute1(i64 %x) {
156-
; CHECK-LABEL: desirable_to_commute1:
157-
; CHECK: // %bb.0:
158-
; CHECK-NEXT: and x0, x0, #0x7fff8
159-
; CHECK-NEXT: ret
160-
%s1 = lshr i64 %x, 3
161-
%a = and i64 %s1, 65535
162-
%s2 = shl i64 %a, 3
163-
ret i64 %s2
164-
}
165-
166-
define i64 @desirable_to_commute2(i64* %p, i64 %i) {
167-
; CHECK-LABEL: desirable_to_commute2:
168-
; CHECK: // %bb.0:
169-
; CHECK-NEXT: and x8, x1, #0x1ff8
170-
; CHECK-NEXT: ldr x0, [x0, x8]
171-
; CHECK-NEXT: ret
172-
%lshr = lshr i64 %i, 3
173-
%and = and i64 %lshr, 1023
174-
%pidx = getelementptr i64, i64* %p, i64 %and
175-
%r = load i64, i64* %pidx
176-
ret i64 %r
177-
}

0 commit comments

Comments
 (0)