Skip to content

Commit 985362e

Browse files
authored
[AArch64][GlobalISel] Avoid running the shl(zext(a), C) -> zext(shl(a, C)) combine. (llvm#67045)
1 parent ddddf7f commit 985362e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,12 @@ class TargetLowering : public TargetLoweringBase {
41474147
return true;
41484148
}
41494149

4150+
/// GlobalISel - return true if it's profitable to perform the combine:
4151+
/// shl ([sza]ext x), y => zext (shl x, y)
4152+
virtual bool isDesirableToPullExtFromShl(const MachineInstr &MI) const {
4153+
return true;
4154+
}
4155+
41504156
// Return AndOrSETCCFoldKind::{AddAnd, ABS} if its desirable to try and
41514157
// optimize LogicOp(SETCC0, SETCC1). An example (what is implemented as of
41524158
// writing this) is:

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,8 @@ void CombinerHelper::applyCombineMulToShl(MachineInstr &MI,
17191719
bool CombinerHelper::matchCombineShlOfExtend(MachineInstr &MI,
17201720
RegisterImmPair &MatchData) {
17211721
assert(MI.getOpcode() == TargetOpcode::G_SHL && KB);
1722+
if (!getTargetLowering().isDesirableToPullExtFromShl(MI))
1723+
return false;
17221724

17231725
Register LHS = MI.getOperand(1).getReg();
17241726

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ class AArch64TargetLowering : public TargetLowering {
690690
bool isDesirableToCommuteWithShift(const SDNode *N,
691691
CombineLevel Level) const override;
692692

693+
bool isDesirableToPullExtFromShl(const MachineInstr &MI) const override {
694+
return false;
695+
}
696+
693697
/// Returns false if N is a bit extraction pattern of (X >> C) & Mask.
694698
bool isDesirableToCommuteXorWithShift(const SDNode *N) const override;
695699

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2+
; RUN: llc %s -verify-machineinstrs -mtriple aarch64-apple-darwin -global-isel -o - | FileCheck %s
3+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
4+
5+
%struct.mszip_stream = type { i32, i32, i8, i32, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, [288 x i8], [32 x i8], [1152 x i16], [128 x i16], [32768 x i8], ptr, ptr }
6+
7+
define i16 @test(i32 %bit_buffer.6.lcssa, ptr %zip, ptr %.out) {
8+
; CHECK-LABEL: test:
9+
; CHECK: ; %bb.0:
10+
; CHECK-NEXT: and w8, w0, #0x1ff
11+
; CHECK-NEXT: add x8, x1, w8, uxtw #1
12+
; CHECK-NEXT: ldrh w0, [x8, #412]
13+
; CHECK-NEXT: ret
14+
%and274 = and i32 %bit_buffer.6.lcssa, 511
15+
%idxprom275 = zext i32 %and274 to i64
16+
%arrayidx276 = getelementptr inbounds %struct.mszip_stream, ptr %zip, i64 0, i32 19, i64 %idxprom275
17+
%ld = load i16, ptr %arrayidx276, align 2
18+
ret i16 %ld
19+
}

0 commit comments

Comments
 (0)