Skip to content

Commit

Permalink
[AArch64][GlobalISel] Avoid running the shl(zext(a), C) -> zext(shl(a…
Browse files Browse the repository at this point in the history
…, C)) combine. (#67045)
  • Loading branch information
aemerson authored Sep 22, 2023
1 parent ddddf7f commit 985362e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,12 @@ class TargetLowering : public TargetLoweringBase {
return true;
}

/// GlobalISel - return true if it's profitable to perform the combine:
/// shl ([sza]ext x), y => zext (shl x, y)
virtual bool isDesirableToPullExtFromShl(const MachineInstr &MI) const {
return true;
}

// Return AndOrSETCCFoldKind::{AddAnd, ABS} if its desirable to try and
// optimize LogicOp(SETCC0, SETCC1). An example (what is implemented as of
// writing this) is:
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,8 @@ void CombinerHelper::applyCombineMulToShl(MachineInstr &MI,
bool CombinerHelper::matchCombineShlOfExtend(MachineInstr &MI,
RegisterImmPair &MatchData) {
assert(MI.getOpcode() == TargetOpcode::G_SHL && KB);
if (!getTargetLowering().isDesirableToPullExtFromShl(MI))
return false;

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

Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,10 @@ class AArch64TargetLowering : public TargetLowering {
bool isDesirableToCommuteWithShift(const SDNode *N,
CombineLevel Level) const override;

bool isDesirableToPullExtFromShl(const MachineInstr &MI) const override {
return false;
}

/// Returns false if N is a bit extraction pattern of (X >> C) & Mask.
bool isDesirableToCommuteXorWithShift(const SDNode *N) const override;

Expand Down
19 changes: 19 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/no-reduce-shl-of-ext.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
; RUN: llc %s -verify-machineinstrs -mtriple aarch64-apple-darwin -global-isel -o - | FileCheck %s
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"

%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 }

define i16 @test(i32 %bit_buffer.6.lcssa, ptr %zip, ptr %.out) {
; CHECK-LABEL: test:
; CHECK: ; %bb.0:
; CHECK-NEXT: and w8, w0, #0x1ff
; CHECK-NEXT: add x8, x1, w8, uxtw #1
; CHECK-NEXT: ldrh w0, [x8, #412]
; CHECK-NEXT: ret
%and274 = and i32 %bit_buffer.6.lcssa, 511
%idxprom275 = zext i32 %and274 to i64
%arrayidx276 = getelementptr inbounds %struct.mszip_stream, ptr %zip, i64 0, i32 19, i64 %idxprom275
%ld = load i16, ptr %arrayidx276, align 2
ret i16 %ld
}

0 comments on commit 985362e

Please sign in to comment.