Skip to content

Commit cead665

Browse files
committed
Merge from 'main' to 'sycl-web' (5 commits)
CONFLICT (content): Merge conflict in llvm/include/llvm/CodeGen/MachinePassRegistry.def
2 parents ac8f814 + 80bb994 commit cead665

36 files changed

+894
-436
lines changed

llvm/include/llvm/CodeGen/CodeGenPassBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/CodeGen/ExpandReductions.h"
2929
#include "llvm/CodeGen/FPBuiltinFnSelection.h"
3030
#include "llvm/CodeGen/GCMetadata.h"
31+
#include "llvm/CodeGen/IndirectBrExpand.h"
3132
#include "llvm/CodeGen/InterleavedAccess.h"
3233
#include "llvm/CodeGen/InterleavedLoadCombine.h"
3334
#include "llvm/CodeGen/JMCInstrumenter.h"

llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ enum {
242242
/// - OpIdx(ULEB128) - Operand index
243243
/// - Val(8) Expected integer
244244
GIM_CheckConstantInt,
245+
246+
/// Check the operand is a specific 8-bit signed integer
247+
/// - InsnID(ULEB128) - Instruction ID
248+
/// - OpIdx(ULEB128) - Operand index
249+
/// - Val(1) Expected integer
250+
GIM_CheckConstantInt8,
251+
245252
/// Check the operand is a specific literal integer (i.e. MO.isImm() or
246253
/// MO.isCImm() is true).
247254
/// - InsnID(ULEB128) - Instruction ID
@@ -399,6 +406,12 @@ enum {
399406
/// - TempRegFlags(2) - The register flags to set
400407
GIR_AddTempRegister,
401408

409+
/// Add a temporary register to the specified instruction without
410+
/// setting any flags.
411+
/// - InsnID(ULEB128) - Instruction ID to modify
412+
/// - TempRegID(ULEB128) - The temporary register ID to add
413+
GIR_AddSimpleTempRegister,
414+
402415
/// Add a temporary register to the specified instruction
403416
/// - InsnID(ULEB128) - Instruction ID to modify
404417
/// - TempRegID(ULEB128) - The temporary register ID to add
@@ -411,6 +424,11 @@ enum {
411424
/// - Imm(8) - The immediate to add
412425
GIR_AddImm,
413426

427+
/// Add signed 8 bit immediate to the specified instruction
428+
/// - InsnID(ULEB128) - Instruction ID to modify
429+
/// - Imm(1) - The immediate to add
430+
GIR_AddImm8,
431+
414432
/// Add an CImm to the specified instruction
415433
/// - InsnID(ULEB128) - Instruction ID to modify
416434
/// - Ty(1) - Type of the constant immediate.

llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,13 @@ bool GIMatchTableExecutor::executeMatchTable(
784784
break;
785785
}
786786

787-
case GIM_CheckConstantInt: {
787+
case GIM_CheckConstantInt:
788+
case GIM_CheckConstantInt8: {
789+
const bool IsInt8 = (MatcherOpcode == GIM_CheckConstantInt8);
790+
788791
uint64_t InsnID = readULEB();
789792
uint64_t OpIdx = readULEB();
790-
uint64_t Value = readU64();
793+
uint64_t Value = IsInt8 ? (int64_t)readS8() : readU64();
791794
DEBUG_WITH_TYPE(TgtExecutor::getName(),
792795
dbgs() << CurrentIdx << ": GIM_CheckConstantInt(MIs["
793796
<< InsnID << "]->getOperand(" << OpIdx
@@ -1157,11 +1160,14 @@ bool GIMatchTableExecutor::executeMatchTable(
11571160
MI->setFlags(MI->getFlags() | State.MIs[OldInsnID]->getFlags());
11581161
break;
11591162
}
1163+
case GIR_AddSimpleTempRegister:
11601164
case GIR_AddTempRegister:
11611165
case GIR_AddTempSubRegister: {
11621166
uint64_t InsnID = readULEB();
11631167
uint64_t TempRegID = readULEB();
1164-
uint16_t TempRegFlags = readU16();
1168+
uint16_t TempRegFlags = 0;
1169+
if (MatcherOpcode != GIR_AddSimpleTempRegister)
1170+
TempRegFlags = readU16();
11651171
uint16_t SubReg = 0;
11661172
if (MatcherOpcode == GIR_AddTempSubRegister)
11671173
SubReg = readU16();
@@ -1179,9 +1185,11 @@ bool GIMatchTableExecutor::executeMatchTable(
11791185
break;
11801186
}
11811187

1188+
case GIR_AddImm8:
11821189
case GIR_AddImm: {
1190+
const bool IsAdd8 = (MatcherOpcode == GIR_AddImm8);
11831191
uint64_t InsnID = readULEB();
1184-
uint64_t Imm = readU64();
1192+
uint64_t Imm = IsAdd8 ? (int64_t)readS8() : readU64();
11851193
assert(OutMIs[InsnID] && "Attempted to add to undefined instruction");
11861194
OutMIs[InsnID].addImm(Imm);
11871195
DEBUG_WITH_TYPE(TgtExecutor::getName(),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- llvm/CodeGen/IndirectBrExpand.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+
9+
#ifndef LLVM_CODEGEN_INDIRECTBREXPAND_H
10+
#define LLVM_CODEGEN_INDIRECTBREXPAND_H
11+
12+
#include "llvm/IR/PassManager.h"
13+
14+
namespace llvm {
15+
16+
class TargetMachine;
17+
18+
class IndirectBrExpandPass : public PassInfoMixin<IndirectBrExpandPass> {
19+
const TargetMachine *TM;
20+
21+
public:
22+
IndirectBrExpandPass(const TargetMachine *TM) : TM(TM) {}
23+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
24+
};
25+
26+
} // namespace llvm
27+
28+
#endif // LLVM_CODEGEN_INDIRECTBREXPAND_H

llvm/include/llvm/CodeGen/MachinePassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ FUNCTION_PASS("expand-large-fp-convert", ExpandLargeFpConvertPass, ())
4949
FUNCTION_PASS("expand-reductions", ExpandReductionsPass, ())
5050
FUNCTION_PASS("expandvp", ExpandVectorPredicationPass, ())
5151
FUNCTION_PASS("fpbuiltin-fn-selection", FPBuiltinFnSelectionPass, ())
52+
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, (TM))
5253
FUNCTION_PASS("interleaved-access", InterleavedAccessPass, (TM))
5354
FUNCTION_PASS("interleaved-load-combine", InterleavedLoadCombinePass, (TM))
5455
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass, ())
@@ -132,7 +133,6 @@ DUMMY_FUNCTION_PASS("atomic-expand", AtomicExpandPass, ())
132133
DUMMY_FUNCTION_PASS("codegenprepare", CodeGenPreparePass, ())
133134
DUMMY_FUNCTION_PASS("expandmemcmp", ExpandMemCmpPass, ())
134135
DUMMY_FUNCTION_PASS("gc-lowering", GCLoweringPass, ())
135-
DUMMY_FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass, ())
136136
DUMMY_FUNCTION_PASS("shadow-stack-gc-lowering", ShadowStackGCLoweringPass, ())
137137
DUMMY_FUNCTION_PASS("stack-protector", StackProtectorPass, ())
138138
#undef DUMMY_FUNCTION_PASS

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void initializeIVUsersWrapperPassPass(PassRegistry&);
131131
void initializeIfConverterPass(PassRegistry&);
132132
void initializeImmutableModuleSummaryIndexWrapperPassPass(PassRegistry&);
133133
void initializeImplicitNullChecksPass(PassRegistry&);
134-
void initializeIndirectBrExpandPassPass(PassRegistry&);
134+
void initializeIndirectBrExpandLegacyPassPass(PassRegistry &);
135135
void initializeInferAddressSpacesPass(PassRegistry&);
136136
void initializeInstSimplifyLegacyPassPass(PassRegistry &);
137137
void initializeInstructionCombiningPassPass(PassRegistry&);

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
5454
initializeHardwareLoopsLegacyPass(Registry);
5555
initializeIfConverterPass(Registry);
5656
initializeImplicitNullChecksPass(Registry);
57-
initializeIndirectBrExpandPassPass(Registry);
57+
initializeIndirectBrExpandLegacyPassPass(Registry);
5858
initializeInterleavedLoadCombinePass(Registry);
5959
initializeInterleavedAccessPass(Registry);
6060
initializeJMCInstrumenterPass(Registry);

llvm/lib/CodeGen/IndirectBrExpandPass.cpp

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/ADT/Sequence.h"
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/Analysis/DomTreeUpdater.h"
32+
#include "llvm/CodeGen/IndirectBrExpand.h"
3233
#include "llvm/CodeGen/TargetPassConfig.h"
3334
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3435
#include "llvm/IR/BasicBlock.h"
@@ -48,14 +49,12 @@ using namespace llvm;
4849

4950
namespace {
5051

51-
class IndirectBrExpandPass : public FunctionPass {
52-
const TargetLowering *TLI = nullptr;
53-
52+
class IndirectBrExpandLegacyPass : public FunctionPass {
5453
public:
5554
static char ID; // Pass identification, replacement for typeid
5655

57-
IndirectBrExpandPass() : FunctionPass(ID) {
58-
initializeIndirectBrExpandPassPass(*PassRegistry::getPassRegistry());
56+
IndirectBrExpandLegacyPass() : FunctionPass(ID) {
57+
initializeIndirectBrExpandLegacyPassPass(*PassRegistry::getPassRegistry());
5958
}
6059

6160
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -67,33 +66,41 @@ class IndirectBrExpandPass : public FunctionPass {
6766

6867
} // end anonymous namespace
6968

70-
char IndirectBrExpandPass::ID = 0;
69+
static bool runImpl(Function &F, const TargetLowering *TLI,
70+
DomTreeUpdater *DTU);
71+
72+
PreservedAnalyses IndirectBrExpandPass::run(Function &F,
73+
FunctionAnalysisManager &FAM) {
74+
auto *STI = TM->getSubtargetImpl(F);
75+
if (!STI->enableIndirectBrExpand())
76+
return PreservedAnalyses::all();
77+
78+
auto *TLI = STI->getTargetLowering();
79+
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
80+
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
81+
82+
bool Changed = runImpl(F, TLI, DT ? &DTU : nullptr);
83+
if (!Changed)
84+
return PreservedAnalyses::all();
85+
PreservedAnalyses PA;
86+
PA.preserve<DominatorTreeAnalysis>();
87+
return PA;
88+
}
89+
90+
char IndirectBrExpandLegacyPass::ID = 0;
7191

72-
INITIALIZE_PASS_BEGIN(IndirectBrExpandPass, DEBUG_TYPE,
92+
INITIALIZE_PASS_BEGIN(IndirectBrExpandLegacyPass, DEBUG_TYPE,
7393
"Expand indirectbr instructions", false, false)
7494
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
75-
INITIALIZE_PASS_END(IndirectBrExpandPass, DEBUG_TYPE,
95+
INITIALIZE_PASS_END(IndirectBrExpandLegacyPass, DEBUG_TYPE,
7696
"Expand indirectbr instructions", false, false)
7797

7898
FunctionPass *llvm::createIndirectBrExpandPass() {
79-
return new IndirectBrExpandPass();
99+
return new IndirectBrExpandLegacyPass();
80100
}
81101

82-
bool IndirectBrExpandPass::runOnFunction(Function &F) {
102+
bool runImpl(Function &F, const TargetLowering *TLI, DomTreeUpdater *DTU) {
83103
auto &DL = F.getParent()->getDataLayout();
84-
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
85-
if (!TPC)
86-
return false;
87-
88-
auto &TM = TPC->getTM<TargetMachine>();
89-
auto &STI = *TM.getSubtargetImpl(F);
90-
if (!STI.enableIndirectBrExpand())
91-
return false;
92-
TLI = STI.getTargetLowering();
93-
94-
std::optional<DomTreeUpdater> DTU;
95-
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
96-
DTU.emplace(DTWP->getDomTree(), DomTreeUpdater::UpdateStrategy::Lazy);
97104

98105
SmallVector<IndirectBrInst *, 1> IndirectBrs;
99106

@@ -268,3 +275,21 @@ bool IndirectBrExpandPass::runOnFunction(Function &F) {
268275

269276
return true;
270277
}
278+
279+
bool IndirectBrExpandLegacyPass::runOnFunction(Function &F) {
280+
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
281+
if (!TPC)
282+
return false;
283+
284+
auto &TM = TPC->getTM<TargetMachine>();
285+
auto &STI = *TM.getSubtargetImpl(F);
286+
if (!STI.enableIndirectBrExpand())
287+
return false;
288+
auto *TLI = STI.getTargetLowering();
289+
290+
std::optional<DomTreeUpdater> DTU;
291+
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
292+
DTU.emplace(DTWP->getDomTree(), DomTreeUpdater::UpdateStrategy::Lazy);
293+
294+
return runImpl(F, TLI, DTU ? &*DTU : nullptr);
295+
}

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP,
12011201
<< printMBBReference(MBB) << '\t' << CopyMI);
12021202
}
12031203

1204+
const bool IsUndefCopy = CopyMI.getOperand(1).isUndef();
1205+
12041206
// Remove CopyMI.
12051207
// Note: This is fine to remove the copy before updating the live-ranges.
12061208
// While updating the live-ranges, we only look at slot indices and
@@ -1214,6 +1216,19 @@ bool RegisterCoalescer::removePartialRedundancy(const CoalescerPair &CP,
12141216
LIS->pruneValue(*static_cast<LiveRange *>(&IntB), CopyIdx.getRegSlot(),
12151217
&EndPoints);
12161218
BValNo->markUnused();
1219+
1220+
if (IsUndefCopy) {
1221+
// We're introducing an undef phi def, and need to set undef on any users of
1222+
// the previously local def to avoid artifically extending the lifetime
1223+
// through the block.
1224+
for (MachineOperand &MO : MRI->use_nodbg_operands(IntB.reg())) {
1225+
const MachineInstr &MI = *MO.getParent();
1226+
SlotIndex UseIdx = LIS->getInstructionIndex(MI);
1227+
if (!IntB.liveAt(UseIdx))
1228+
MO.setIsUndef(true);
1229+
}
1230+
}
1231+
12171232
// Extend IntB to the EndPoints of its original live interval.
12181233
LIS->extendToIndices(IntB, EndPoints);
12191234

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "llvm/CodeGen/ExpandLargeFpConvert.h"
7979
#include "llvm/CodeGen/GCMetadata.h"
8080
#include "llvm/CodeGen/HardwareLoops.h"
81+
#include "llvm/CodeGen/IndirectBrExpand.h"
8182
#include "llvm/CodeGen/InterleavedAccess.h"
8283
#include "llvm/CodeGen/InterleavedLoadCombine.h"
8384
#include "llvm/CodeGen/JMCInstrumenter.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ FUNCTION_PASS("guard-widening", GuardWideningPass())
330330
FUNCTION_PASS("gvn-hoist", GVNHoistPass())
331331
FUNCTION_PASS("gvn-sink", GVNSinkPass())
332332
FUNCTION_PASS("helloworld", HelloWorldPass())
333+
FUNCTION_PASS("indirectbr-expand", IndirectBrExpandPass(TM))
333334
FUNCTION_PASS("infer-address-spaces", InferAddressSpacesPass())
334335
FUNCTION_PASS("infer-alignment", InferAlignmentPass())
335336
FUNCTION_PASS("inject-tli-mappings", InjectTLIMappings())
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
2+
# RUN: llc -mtriple=x86_64-pc-linux-gnu -run-pass=register-coalescer -verify-coalescing -o - %s | FileCheck %s
3+
4+
# Check for "Live range continues after dead def flag".
5+
6+
# There are 2 copies of undef, but the registers also appear to be
7+
# live due to block live outs, and thus were not deleted as
8+
# eliminateUndefCopy only considered the live range, and not the undef
9+
# flag.
10+
#
11+
# removePartialRedundancy would move the COPY undef %0 in bb.1 to
12+
# bb.0. The live range of %1 would then be extended to be live out of
13+
# %bb.1 for the backedge phi. This would then fail the verifier, since
14+
# the dead flag was no longer valid. This was fixed by directly
15+
# considering the undef flag to avoid considering this special case.
16+
17+
---
18+
name: partial_redundancy_coalesce_undef_copy_live_out
19+
tracksRegLiveness: true
20+
body: |
21+
; CHECK-LABEL: name: partial_redundancy_coalesce_undef_copy_live_out
22+
; CHECK: bb.0:
23+
; CHECK-NEXT: successors: %bb.1(0x80000000)
24+
; CHECK-NEXT: liveins: $rdi
25+
; CHECK-NEXT: {{ $}}
26+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $rdi
27+
; CHECK-NEXT: {{ $}}
28+
; CHECK-NEXT: bb.1:
29+
; CHECK-NEXT: successors: %bb.1(0x80000000)
30+
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: dead [[XOR32ri:%[0-9]+]]:gr32 = XOR32ri undef [[XOR32ri]], 1, implicit-def dead $eflags
32+
; CHECK-NEXT: dead [[MOV32rr:%[0-9]+]]:gr32 = MOV32rr [[COPY]]
33+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = IMPLICIT_DEF
34+
; CHECK-NEXT: JMP_1 %bb.1
35+
bb.0:
36+
liveins: $rdi
37+
38+
%0:gr32 = COPY $rdi
39+
40+
bb.1:
41+
%1:gr32 = COPY undef %0
42+
dead %1:gr32 = XOR32ri %1, 1, implicit-def dead $eflags
43+
dead %2:gr32 = MOV32rr killed %0
44+
%0:gr32 = COPY killed undef %1
45+
JMP_1 %bb.1
46+
47+
...

0 commit comments

Comments
 (0)