Skip to content

Commit 652e7a5

Browse files
committed
Squashing wip branch.
1 parent 67e73ba commit 652e7a5

26 files changed

+4173
-184
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry &);
237237
LLVM_ABI void initializeOptimizePHIsLegacyPass(PassRegistry &);
238238
LLVM_ABI void initializePEILegacyPass(PassRegistry &);
239239
LLVM_ABI void initializePHIEliminationPass(PassRegistry &);
240+
LLVM_ABI void initializePackedIntegerCombineLegacyPassPass(PassRegistry &);
240241
LLVM_ABI void initializePartiallyInlineLibCallsLegacyPassPass(PassRegistry &);
241242
LLVM_ABI void initializePatchableFunctionLegacyPass(PassRegistry &);
242243
LLVM_ABI void initializePeepholeOptimizerLegacyPass(PassRegistry &);

llvm/include/llvm/Transforms/Scalar.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ LLVM_ABI FunctionPass *
154154
createInferAddressSpacesPass(unsigned AddressSpace = ~0u);
155155
LLVM_ABI extern char &InferAddressSpacesID;
156156

157+
//===----------------------------------------------------------------------===//
158+
//
159+
// PackedIntegerCombinePass - Tracks individual bytes through instructions to
160+
// systematically identify redundant byte packing or unpacking operations.
161+
//
162+
LLVM_ABI FunctionPass *createPackedIntegerCombinePass();
163+
157164
//===----------------------------------------------------------------------===//
158165
//
159166
// PartiallyInlineLibCalls - Tries to inline the fast path of library
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===- PackedIntegerCombinePass.h -------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
/// \file
9+
///
10+
/// This file provides the interface for LLVM's Packed Integer Combine pass.
11+
/// This pass tries to treat integers as packed chunks of individual bytes,
12+
/// and leverage this to coalesce needlessly fragmented
13+
/// computations.
14+
///
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef LLVM_TRANSFORMS_SCALAR_PACKEDINTCOMBINE_H
18+
#define LLVM_TRANSFORMS_SCALAR_PACKEDINTCOMBINE_H
19+
20+
#include "llvm/IR/PassManager.h"
21+
22+
namespace llvm {
23+
24+
class PackedIntegerCombinePass
25+
: public PassInfoMixin<PackedIntegerCombinePass> {
26+
public:
27+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
28+
};
29+
30+
} // end namespace llvm
31+
32+
#endif // LLVM_TRANSFORMS_SCALAR_PACKEDINTCOMBINE_H

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313
#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
314314
#include "llvm/Transforms/Scalar/NaryReassociate.h"
315315
#include "llvm/Transforms/Scalar/NewGVN.h"
316+
#include "llvm/Transforms/Scalar/PackedIntegerCombinePass.h"
316317
#include "llvm/Transforms/Scalar/PartiallyInlineLibCalls.h"
317318
#include "llvm/Transforms/Scalar/PlaceSafepoints.h"
318319
#include "llvm/Transforms/Scalar/Reassociate.h"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"
122122
#include "llvm/Transforms/Scalar/MergedLoadStoreMotion.h"
123123
#include "llvm/Transforms/Scalar/NewGVN.h"
124+
#include "llvm/Transforms/Scalar/PackedIntegerCombinePass.h"
124125
#include "llvm/Transforms/Scalar/Reassociate.h"
125126
#include "llvm/Transforms/Scalar/SCCP.h"
126127
#include "llvm/Transforms/Scalar/SROA.h"
@@ -542,6 +543,9 @@ PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
542543
// opportunities that creates).
543544
FPM.addPass(BDCEPass());
544545

546+
// Simplify bit-packed operations before cleaning up with instcombine.
547+
FPM.addPass(PackedIntegerCombinePass());
548+
545549
// Run instcombine after redundancy and dead bit elimination to exploit
546550
// opportunities opened up by them.
547551
FPM.addPass(InstCombinePass());
@@ -743,6 +747,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
743747
// opportunities that creates).
744748
FPM.addPass(BDCEPass());
745749

750+
// Simplify bit-packed operations before cleaning up with instcombine.
751+
FPM.addPass(PackedIntegerCombinePass());
752+
746753
// Run instcombine after redundancy and dead bit elimination to exploit
747754
// opportunities opened up by them.
748755
FPM.addPass(InstCombinePass());

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ FUNCTION_PASS("objc-arc", ObjCARCOptPass())
476476
FUNCTION_PASS("objc-arc-contract", ObjCARCContractPass())
477477
FUNCTION_PASS("objc-arc-expand", ObjCARCExpandPass())
478478
FUNCTION_PASS("pa-eval", PAEvalPass())
479+
FUNCTION_PASS("packedintcombine", PackedIntegerCombinePass())
479480
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
480481
FUNCTION_PASS("pgo-memop-opt", PGOMemOPSizeOpt())
481482
FUNCTION_PASS("place-safepoints", PlaceSafepointsPass())

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#include "llvm/Transforms/Scalar/InferAddressSpaces.h"
105105
#include "llvm/Transforms/Scalar/LoopDataPrefetch.h"
106106
#include "llvm/Transforms/Scalar/NaryReassociate.h"
107+
#include "llvm/Transforms/Scalar/PackedIntegerCombinePass.h"
107108
#include "llvm/Transforms/Scalar/SeparateConstOffsetFromGEP.h"
108109
#include "llvm/Transforms/Scalar/Sink.h"
109110
#include "llvm/Transforms/Scalar/StraightLineStrengthReduce.h"
@@ -1378,8 +1379,11 @@ void AMDGPUPassConfig::addCodeGenPrepare() {
13781379

13791380
TargetPassConfig::addCodeGenPrepare();
13801381

1381-
if (isPassEnabled(EnableLoadStoreVectorizer))
1382+
if (isPassEnabled(EnableLoadStoreVectorizer)) {
13821383
addPass(createLoadStoreVectorizerPass());
1384+
// LSV pass opens up more opportunities for packed integer combining.
1385+
addPass(createPackedIntegerCombinePass());
1386+
}
13831387

13841388
// LowerSwitch pass may introduce unreachable blocks that can
13851389
// cause unexpected behavior for subsequent passes. Placing it
@@ -2101,8 +2105,11 @@ void AMDGPUCodeGenPassBuilder::addCodeGenPrepare(AddIRPass &addPass) const {
21012105

21022106
Base::addCodeGenPrepare(addPass);
21032107

2104-
if (isPassEnabled(EnableLoadStoreVectorizer))
2108+
if (isPassEnabled(EnableLoadStoreVectorizer)) {
21052109
addPass(LoadStoreVectorizerPass());
2110+
// LSV pass opens up more opportunities for packed integer combining.
2111+
addPass(PackedIntegerCombinePass());
2112+
}
21062113

21072114
// LowerSwitch pass may introduce unreachable blocks that can cause unexpected
21082115
// behavior for subsequent passes. Placing it here seems better that these

llvm/lib/Transforms/Scalar/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ add_llvm_component_library(LLVMScalarOpts
6161
NaryReassociate.cpp
6262
NewGVN.cpp
6363
PartiallyInlineLibCalls.cpp
64+
PackedIntegerCombinePass.cpp
6465
PlaceSafepoints.cpp
6566
Reassociate.cpp
6667
Reg2Mem.cpp

0 commit comments

Comments
 (0)