-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[AArch64][ARM] Move ARM-specific InstCombine transforms into Transforms/Utils
#169589
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
Merged
+223
−107
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
852e4d3
[AArch64][ARM] Move ARM-specific InstCombine transforms to new module
valadaptive 234164f
[AArch64][ARM] !Zext -> IsSigned
valadaptive e53963f
[AArch64][ARM] Make simplifyNeonTbl1 behave like the other transforms
valadaptive 40b6ac3
[AArch64][ARM] Move the transforms to Transforms/Utils
valadaptive 82fec7b
[ARM] Remove redundant -mtriple=arm from RUN line
valadaptive c52757d
[AArch64][ARM] Shorten file descriptions
valadaptive 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
57 changes: 57 additions & 0 deletions
57
llvm/include/llvm/Transforms/Utils/ARMCommonInstCombineIntrinsic.h
This file contains hidden or 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,57 @@ | ||
| //===- ARMCommonInstCombineIntrinsic.h - | ||
| // instCombineIntrinsic opts for both ARM and AArch64 -----------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains optimizations for ARM and AArch64 intrinsics that | ||
| /// are shared between both architectures. These functions can be called from: | ||
| /// - ARM TTI's instCombineIntrinsic (for arm_neon_* intrinsics) | ||
| /// - AArch64 TTI's instCombineIntrinsic (for aarch64_neon_* and aarch64_sve_* | ||
| /// intrinsics) | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_TRANSFORMS_UTILS_ARMCOMMONINSTCOMBINEINTRINSIC_H | ||
| #define LLVM_TRANSFORMS_UTILS_ARMCOMMONINSTCOMBINEINTRINSIC_H | ||
|
|
||
| #include "llvm/IR/IntrinsicInst.h" | ||
| #include "llvm/IR/Value.h" | ||
| #include "llvm/Transforms/InstCombine/InstCombiner.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| namespace ARMCommon { | ||
|
|
||
| /// Convert a table lookup to shufflevector if the mask is constant. | ||
| /// This could benefit tbl1 if the mask is { 7,6,5,4,3,2,1,0 }, in | ||
| /// which case we could lower the shufflevector with rev64 instructions | ||
| /// as it's actually a byte reverse. | ||
| Instruction *simplifyNeonTbl1(IntrinsicInst &II, InstCombiner &IC); | ||
|
|
||
| /// Simplify NEON multiply-long intrinsics (smull, umull). | ||
| /// These intrinsics perform widening multiplies: they multiply two vectors of | ||
| /// narrow integers and produce a vector of wider integers. This function | ||
| /// performs algebraic simplifications: | ||
| /// 1. Multiply by zero => zero vector | ||
| /// 2. Multiply by one => zero/sign-extend the non-one operand | ||
| /// 3. Both operands constant => regular multiply that can be constant-folded | ||
| /// later | ||
| Instruction *simplifyNeonMultiply(IntrinsicInst &II, InstCombiner &IC, | ||
| bool IsSigned); | ||
|
|
||
| /// Simplify AES encryption/decryption intrinsics (AESE, AESD). | ||
| /// | ||
| /// ARM's AES instructions (AESE/AESD) XOR the data and the key, provided as | ||
| /// separate arguments, before performing the encryption/decryption operation. | ||
| /// We can fold that "internal" XOR with a previous one. | ||
| Instruction *simplifyAES(IntrinsicInst &II, InstCombiner &IC); | ||
|
|
||
| } // namespace ARMCommon | ||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_TRANSFORMS_UTILS_ARMCOMMONINSTCOMBINEINTRINSIC_H | ||
This file contains hidden or 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 hidden or 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 hidden or 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
136 changes: 136 additions & 0 deletions
136
llvm/lib/Transforms/Utils/ARMCommonInstCombineIntrinsic.cpp
This file contains hidden or 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,136 @@ | ||
| //===- ARMCommonInstCombineIntrinsic.cpp - | ||
| // instCombineIntrinsic opts for both ARM and AArch64 ---===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| /// | ||
| /// \file | ||
| /// This file contains optimizations for ARM and AArch64 intrinsics that | ||
| /// are shared between both architectures. These functions can be called from: | ||
| /// - ARM TTI's instCombineIntrinsic (for arm_neon_* intrinsics) | ||
| /// - AArch64 TTI's instCombineIntrinsic (for aarch64_neon_* and aarch64_sve_* | ||
| /// intrinsics) | ||
| /// | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "llvm/Transforms/Utils/ARMCommonInstCombineIntrinsic.h" | ||
| #include "llvm/IR/Constants.h" | ||
| #include "llvm/IR/IntrinsicInst.h" | ||
| #include "llvm/IR/Value.h" | ||
| #include "llvm/Transforms/InstCombine/InstCombiner.h" | ||
|
|
||
| using namespace llvm; | ||
| using namespace llvm::PatternMatch; | ||
|
|
||
| namespace llvm { | ||
| namespace ARMCommon { | ||
|
|
||
| /// Convert a table lookup to shufflevector if the mask is constant. | ||
| /// This could benefit tbl1 if the mask is { 7,6,5,4,3,2,1,0 }, in | ||
| /// which case we could lower the shufflevector with rev64 instructions | ||
| /// as it's actually a byte reverse. | ||
| Instruction *simplifyNeonTbl1(IntrinsicInst &II, InstCombiner &IC) { | ||
| // Bail out if the mask is not a constant. | ||
| auto *C = dyn_cast<Constant>(II.getArgOperand(1)); | ||
| if (!C) | ||
| return nullptr; | ||
|
|
||
| auto *VecTy = cast<FixedVectorType>(II.getType()); | ||
| unsigned NumElts = VecTy->getNumElements(); | ||
|
|
||
| // Only perform this transformation for <8 x i8> vector types. | ||
| if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8) | ||
| return nullptr; | ||
|
|
||
| int Indexes[8]; | ||
|
|
||
| for (unsigned I = 0; I < NumElts; ++I) { | ||
| Constant *COp = C->getAggregateElement(I); | ||
|
|
||
| if (!COp || !isa<ConstantInt>(COp)) | ||
| return nullptr; | ||
|
|
||
| Indexes[I] = cast<ConstantInt>(COp)->getLimitedValue(); | ||
|
|
||
| // Make sure the mask indices are in range. | ||
| if ((unsigned)Indexes[I] >= NumElts) | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto *V1 = II.getArgOperand(0); | ||
| auto *V2 = Constant::getNullValue(V1->getType()); | ||
| Value *Shuf = IC.Builder.CreateShuffleVector(V1, V2, ArrayRef(Indexes)); | ||
| return IC.replaceInstUsesWith(II, Shuf); | ||
| } | ||
|
|
||
| /// Simplify NEON multiply-long intrinsics (smull, umull). | ||
| /// These intrinsics perform widening multiplies: they multiply two vectors of | ||
| /// narrow integers and produce a vector of wider integers. This function | ||
| /// performs algebraic simplifications: | ||
| /// 1. Multiply by zero => zero vector | ||
| /// 2. Multiply by one => zero/sign-extend the non-one operand | ||
| /// 3. Both operands constant => regular multiply that can be constant-folded | ||
| /// later | ||
| Instruction *simplifyNeonMultiply(IntrinsicInst &II, InstCombiner &IC, | ||
| bool IsSigned) { | ||
| Value *Arg0 = II.getArgOperand(0); | ||
| Value *Arg1 = II.getArgOperand(1); | ||
|
|
||
| // Handle mul by zero first: | ||
| if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) { | ||
| return IC.replaceInstUsesWith(II, ConstantAggregateZero::get(II.getType())); | ||
| } | ||
|
|
||
| // Check for constant LHS & RHS - in this case we just simplify. | ||
| VectorType *NewVT = cast<VectorType>(II.getType()); | ||
| if (Constant *CV0 = dyn_cast<Constant>(Arg0)) { | ||
| if (Constant *CV1 = dyn_cast<Constant>(Arg1)) { | ||
| Value *V0 = IC.Builder.CreateIntCast(CV0, NewVT, IsSigned); | ||
| Value *V1 = IC.Builder.CreateIntCast(CV1, NewVT, IsSigned); | ||
| return IC.replaceInstUsesWith(II, IC.Builder.CreateMul(V0, V1)); | ||
| } | ||
|
|
||
| // Couldn't simplify - canonicalize constant to the RHS. | ||
| std::swap(Arg0, Arg1); | ||
| } | ||
|
|
||
| // Handle mul by one: | ||
| if (Constant *CV1 = dyn_cast<Constant>(Arg1)) | ||
| if (ConstantInt *Splat = | ||
| dyn_cast_or_null<ConstantInt>(CV1->getSplatValue())) | ||
| if (Splat->isOne()) | ||
| return CastInst::CreateIntegerCast(Arg0, II.getType(), IsSigned); | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| /// Simplify AES encryption/decryption intrinsics (AESE, AESD). | ||
| /// | ||
| /// ARM's AES instructions (AESE/AESD) XOR the data and the key, provided as | ||
| /// separate arguments, before performing the encryption/decryption operation. | ||
| /// We can fold that "internal" XOR with a previous one. | ||
| Instruction *simplifyAES(IntrinsicInst &II, InstCombiner &IC) { | ||
| Value *DataArg = II.getArgOperand(0); | ||
| Value *KeyArg = II.getArgOperand(1); | ||
|
|
||
| // Accept zero on either operand. | ||
| if (!match(KeyArg, m_ZeroInt())) | ||
| std::swap(KeyArg, DataArg); | ||
|
|
||
| // Try to use the builtin XOR in AESE and AESD to eliminate a prior XOR | ||
| Value *Data, *Key; | ||
| if (match(KeyArg, m_ZeroInt()) && | ||
| match(DataArg, m_Xor(m_Value(Data), m_Value(Key)))) { | ||
| IC.replaceOperand(II, 0, Data); | ||
| IC.replaceOperand(II, 1, Key); | ||
| return &II; | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| } // namespace ARMCommon | ||
| } // namespace llvm |
This file contains hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
llvm/test/Transforms/InstCombine/ARM/2012-04-23-Neon-Intrinsics.ll
This file contains hidden or 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 hidden or 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.
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.
I don't think I've seen files overflow the first line before. Maybe just rely on the \file description below and keep this to a single line?
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.
I've shortened it to just "Shared ARM/AArch64 opts". That's the longest it can be without overflow.