-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combine (shl (and x, imm1), imm2) to (shl x, imm2) #246
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
llvm/test/CodeGen/AArch64/GlobalISel/combine-shl-and.mir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# | ||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# Modifications (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates | ||
# RUN: llc -mtriple aarch64 -run-pass=aarch64-postlegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s | ||
|
||
--- | ||
name: test_combine_shl_of_and_I16_shift_8 | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I16_shift_8 | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 8 | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL [[TRUNC]], [[C]](s16) | ||
; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s32) = G_SEXT [[SHL]](s16) | ||
; CHECK-NEXT: $w0 = COPY [[SEXT]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s16) = G_CONSTANT i16 8 | ||
%2:_(s16) = G_CONSTANT i16 255 | ||
%3:_(s16) = G_TRUNC %0 | ||
%4:_(s16) = G_AND %3, %2 | ||
%5:_(s16) = G_SHL %4, %1 | ||
%6:_(s32) = G_SEXT %5 | ||
$w0 = COPY %6(s32) | ||
... | ||
--- | ||
# Negative test case: Here we're trying to shift less than half size. | ||
name: test_combine_shl_of_and_I16_shift_4_neg | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I16_shift_4_neg | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 4 | ||
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s16) = G_CONSTANT i16 15 | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s16) = G_AND [[TRUNC]], [[C1]] | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL [[AND]], [[C]](s16) | ||
; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s32) = G_SEXT [[SHL]](s16) | ||
; CHECK-NEXT: $w0 = COPY [[SEXT]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s16) = G_CONSTANT i16 4 | ||
%2:_(s16) = G_CONSTANT i16 15 | ||
%3:_(s16) = G_TRUNC %0 | ||
%4:_(s16) = G_AND %3, %2 | ||
%5:_(s16) = G_SHL %4, %1 | ||
%6:_(s32) = G_SEXT %5 | ||
$w0 = COPY %6(s32) | ||
... | ||
--- | ||
name: test_combine_shl_of_and_I32_shift_16 | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I32_shift_16 | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16 | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32) | ||
; CHECK-NEXT: $w0 = COPY [[SHL]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s32) = G_CONSTANT i32 16 | ||
%2:_(s32) = G_CONSTANT i32 65535 | ||
%3:_(s32) = G_AND %0, %2 | ||
%4:_(s32) = G_SHL %3, %1 | ||
$w0 = COPY %4(s32) | ||
... | ||
--- | ||
name: test_combine_shl_of_and_I32_shift_24 | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I32_shift_24 | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 24 | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32) | ||
; CHECK-NEXT: $w0 = COPY [[SHL]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s32) = G_CONSTANT i32 24 | ||
%2:_(s32) = G_CONSTANT i32 16777215 | ||
%3:_(s32) = G_AND %0, %2 | ||
%4:_(s32) = G_SHL %3, %1 | ||
$w0 = COPY %4(s32) | ||
... | ||
--- | ||
# Negative test case: Here we're trying to shift less than half size. | ||
name: test_combine_shl_of_and_I32_shift_8_neg | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I32_shift_8_neg | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 8 | ||
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 255 | ||
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C1]] | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND]], [[C]](s32) | ||
; CHECK-NEXT: $w0 = COPY [[SHL]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s32) = G_CONSTANT i32 8 | ||
%2:_(s32) = G_CONSTANT i32 255 | ||
%3:_(s32) = G_AND %0, %2 | ||
%4:_(s32) = G_SHL %3, %1 | ||
$w0 = COPY %4(s32) | ||
... | ||
--- | ||
# Negative test case: The AND and SHL operations cannot be combined because imm1 (255) and imm2 (16) do not satisfy the condition (~imm1 << imm2) = 0 | ||
name: test_combine_shl_of_and_I32_shift_16_neg | ||
legalized: true | ||
tracksRegLiveness: true | ||
body: | | ||
bb.0.entry: | ||
liveins: $w0 | ||
; CHECK-LABEL: name: test_combine_shl_of_and_I32_shift_16_neg | ||
; CHECK: liveins: $w0 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0 | ||
; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16 | ||
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 255 | ||
; CHECK-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[COPY]], [[C1]] | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[AND]], [[C]](s32) | ||
; CHECK-NEXT: $w0 = COPY [[SHL]](s32) | ||
%0:_(s32) = COPY $w0 | ||
%1:_(s32) = G_CONSTANT i32 16 | ||
%2:_(s32) = G_CONSTANT i32 255 | ||
%3:_(s32) = G_AND %0, %2 | ||
%4:_(s32) = G_SHL %3, %1 | ||
$w0 = COPY %4(s32) | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think the mOneNonDBGUse condition is tested, but I also don't think it's necessary. We just remove a use of the AND. If it's the last use, DCE will remove it; if it's not, it will serve the other uses.