Skip to content

Commit f741851

Browse files
committed
Revert "[AArch64][ARM] Move ARM-specific InstCombine transforms into Transforms/Utils (#169589)"
This reverts commit 1c32b6f due to failures on BUILD_SHARED_LIBS builds.
1 parent e8bf011 commit f741851

File tree

10 files changed

+107
-223
lines changed

10 files changed

+107
-223
lines changed

llvm/include/llvm/Transforms/Utils/ARMCommonInstCombineIntrinsic.h

Lines changed: 0 additions & 56 deletions
This file was deleted.

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "llvm/Support/Debug.h"
2626
#include "llvm/TargetParser/AArch64TargetParser.h"
2727
#include "llvm/Transforms/InstCombine/InstCombiner.h"
28-
#include "llvm/Transforms/Utils/ARMCommonInstCombineIntrinsic.h"
2928
#include "llvm/Transforms/Utils/UnrollLoop.h"
3029
#include "llvm/Transforms/Vectorize/LoopVectorizationLegality.h"
3130
#include <algorithm>
@@ -2874,18 +2873,6 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC,
28742873
case Intrinsic::aarch64_neon_fmaxnm:
28752874
case Intrinsic::aarch64_neon_fminnm:
28762875
return instCombineMaxMinNM(IC, II);
2877-
case Intrinsic::aarch64_neon_tbl1:
2878-
return ARMCommon::simplifyNeonTbl1(II, IC);
2879-
case Intrinsic::aarch64_neon_smull:
2880-
case Intrinsic::aarch64_neon_umull: {
2881-
bool IsSigned = IID == Intrinsic::aarch64_neon_smull;
2882-
return ARMCommon::simplifyNeonMultiply(II, IC, IsSigned);
2883-
}
2884-
case Intrinsic::aarch64_crypto_aesd:
2885-
case Intrinsic::aarch64_crypto_aese:
2886-
case Intrinsic::aarch64_sve_aesd:
2887-
case Intrinsic::aarch64_sve_aese:
2888-
return ARMCommon::simplifyAES(II, IC);
28892876
case Intrinsic::aarch64_sve_convert_from_svbool:
28902877
return instCombineConvertFromSVBool(IC, II);
28912878
case Intrinsic::aarch64_sve_dup:

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "llvm/Target/TargetMachine.h"
3232
#include "llvm/TargetParser/SubtargetFeature.h"
3333
#include "llvm/Transforms/InstCombine/InstCombiner.h"
34-
#include "llvm/Transforms/Utils/ARMCommonInstCombineIntrinsic.h"
3534
#include "llvm/Transforms/Utils/Local.h"
3635
#include "llvm/Transforms/Utils/LoopUtils.h"
3736
#include "llvm/Transforms/Vectorize/LoopVectorizationLegality.h"
@@ -188,19 +187,6 @@ ARMTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
188187
break;
189188
}
190189

191-
case Intrinsic::arm_neon_vtbl1:
192-
return ARMCommon::simplifyNeonTbl1(II, IC);
193-
194-
case Intrinsic::arm_neon_vmulls:
195-
case Intrinsic::arm_neon_vmullu: {
196-
bool IsSigned = IID == Intrinsic::arm_neon_vmulls;
197-
return ARMCommon::simplifyNeonMultiply(II, IC, IsSigned);
198-
}
199-
200-
case Intrinsic::arm_neon_aesd:
201-
case Intrinsic::arm_neon_aese:
202-
return ARMCommon::simplifyAES(II, IC);
203-
204190
case Intrinsic::arm_mve_pred_i2v: {
205191
Value *Arg = II.getArgOperand(0);
206192
Value *ArgArg;

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,44 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
737737
return nullptr;
738738
}
739739

740+
/// Convert a table lookup to shufflevector if the mask is constant.
741+
/// This could benefit tbl1 if the mask is { 7,6,5,4,3,2,1,0 }, in
742+
/// which case we could lower the shufflevector with rev64 instructions
743+
/// as it's actually a byte reverse.
744+
static Value *simplifyNeonTbl1(const IntrinsicInst &II,
745+
InstCombiner::BuilderTy &Builder) {
746+
// Bail out if the mask is not a constant.
747+
auto *C = dyn_cast<Constant>(II.getArgOperand(1));
748+
if (!C)
749+
return nullptr;
750+
751+
auto *VecTy = cast<FixedVectorType>(II.getType());
752+
unsigned NumElts = VecTy->getNumElements();
753+
754+
// Only perform this transformation for <8 x i8> vector types.
755+
if (!VecTy->getElementType()->isIntegerTy(8) || NumElts != 8)
756+
return nullptr;
757+
758+
int Indexes[8];
759+
760+
for (unsigned I = 0; I < NumElts; ++I) {
761+
Constant *COp = C->getAggregateElement(I);
762+
763+
if (!COp || !isa<ConstantInt>(COp))
764+
return nullptr;
765+
766+
Indexes[I] = cast<ConstantInt>(COp)->getLimitedValue();
767+
768+
// Make sure the mask indices are in range.
769+
if ((unsigned)Indexes[I] >= NumElts)
770+
return nullptr;
771+
}
772+
773+
auto *V1 = II.getArgOperand(0);
774+
auto *V2 = Constant::getNullValue(V1->getType());
775+
return Builder.CreateShuffleVector(V1, V2, ArrayRef(Indexes));
776+
}
777+
740778
// Returns true iff the 2 intrinsics have the same operands, limiting the
741779
// comparison to the first NumOperands.
742780
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E,
@@ -3128,6 +3166,72 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
31283166
Intrinsic::getOrInsertDeclaration(II->getModule(), NewIntrin);
31293167
return CallInst::Create(NewFn, CallArgs);
31303168
}
3169+
case Intrinsic::arm_neon_vtbl1:
3170+
case Intrinsic::aarch64_neon_tbl1:
3171+
if (Value *V = simplifyNeonTbl1(*II, Builder))
3172+
return replaceInstUsesWith(*II, V);
3173+
break;
3174+
3175+
case Intrinsic::arm_neon_vmulls:
3176+
case Intrinsic::arm_neon_vmullu:
3177+
case Intrinsic::aarch64_neon_smull:
3178+
case Intrinsic::aarch64_neon_umull: {
3179+
Value *Arg0 = II->getArgOperand(0);
3180+
Value *Arg1 = II->getArgOperand(1);
3181+
3182+
// Handle mul by zero first:
3183+
if (isa<ConstantAggregateZero>(Arg0) || isa<ConstantAggregateZero>(Arg1)) {
3184+
return replaceInstUsesWith(CI, ConstantAggregateZero::get(II->getType()));
3185+
}
3186+
3187+
// Check for constant LHS & RHS - in this case we just simplify.
3188+
bool Zext = (IID == Intrinsic::arm_neon_vmullu ||
3189+
IID == Intrinsic::aarch64_neon_umull);
3190+
VectorType *NewVT = cast<VectorType>(II->getType());
3191+
if (Constant *CV0 = dyn_cast<Constant>(Arg0)) {
3192+
if (Constant *CV1 = dyn_cast<Constant>(Arg1)) {
3193+
Value *V0 = Builder.CreateIntCast(CV0, NewVT, /*isSigned=*/!Zext);
3194+
Value *V1 = Builder.CreateIntCast(CV1, NewVT, /*isSigned=*/!Zext);
3195+
return replaceInstUsesWith(CI, Builder.CreateMul(V0, V1));
3196+
}
3197+
3198+
// Couldn't simplify - canonicalize constant to the RHS.
3199+
std::swap(Arg0, Arg1);
3200+
}
3201+
3202+
// Handle mul by one:
3203+
if (Constant *CV1 = dyn_cast<Constant>(Arg1))
3204+
if (ConstantInt *Splat =
3205+
dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
3206+
if (Splat->isOne())
3207+
return CastInst::CreateIntegerCast(Arg0, II->getType(),
3208+
/*isSigned=*/!Zext);
3209+
3210+
break;
3211+
}
3212+
case Intrinsic::arm_neon_aesd:
3213+
case Intrinsic::arm_neon_aese:
3214+
case Intrinsic::aarch64_crypto_aesd:
3215+
case Intrinsic::aarch64_crypto_aese:
3216+
case Intrinsic::aarch64_sve_aesd:
3217+
case Intrinsic::aarch64_sve_aese: {
3218+
Value *DataArg = II->getArgOperand(0);
3219+
Value *KeyArg = II->getArgOperand(1);
3220+
3221+
// Accept zero on either operand.
3222+
if (!match(KeyArg, m_ZeroInt()))
3223+
std::swap(KeyArg, DataArg);
3224+
3225+
// Try to use the builtin XOR in AESE and AESD to eliminate a prior XOR
3226+
Value *Data, *Key;
3227+
if (match(KeyArg, m_ZeroInt()) &&
3228+
match(DataArg, m_Xor(m_Value(Data), m_Value(Key)))) {
3229+
replaceOperand(*II, 0, Data);
3230+
replaceOperand(*II, 1, Key);
3231+
return II;
3232+
}
3233+
break;
3234+
}
31313235
case Intrinsic::hexagon_V6_vandvrt:
31323236
case Intrinsic::hexagon_V6_vandvrt_128B: {
31333237
// Simplify Q -> V -> Q conversion.

llvm/lib/Transforms/Utils/ARMCommonInstCombineIntrinsic.cpp

Lines changed: 0 additions & 135 deletions
This file was deleted.

llvm/lib/Transforms/Utils/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
add_llvm_component_library(LLVMTransformUtils
22
AddDiscriminators.cpp
33
AMDGPUEmitPrintf.cpp
4-
ARMCommonInstCombineIntrinsic.cpp
54
ASanStackFrameLayout.cpp
65
AssumeBundleBuilder.cpp
76
BasicBlockUtils.cpp

llvm/test/Transforms/InstCombine/AArch64/aes-intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt --mtriple=aarch64 -S -passes=instcombine < %s | FileCheck %s
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
33
; ARM64 AES intrinsic variants
44

55
define <16 x i8> @combineXorAeseZeroARM64(<16 x i8> %data, <16 x i8> %key) {

llvm/test/Transforms/InstCombine/ARM/2012-04-23-Neon-Intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -mtriple=arm -S -passes=instcombine < %s | FileCheck %s
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
33

44
define <4 x i32> @mulByZero(<4 x i16> %x) nounwind readnone ssp {
55
; CHECK-LABEL: define <4 x i32> @mulByZero(

llvm/test/Transforms/InstCombine/ARM/aes-intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -mtriple=arm -S -passes=instcombine < %s | FileCheck %s
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
33
; ARM AES intrinsic variants
44

55
define <16 x i8> @combineXorAeseZeroARM(<16 x i8> %data, <16 x i8> %key) {

0 commit comments

Comments
 (0)