Skip to content

Commit 370eaf1

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-verify-def-use-phi
2 parents 8e60892 + ba2dacd commit 370eaf1

File tree

15 files changed

+213
-36
lines changed

15 files changed

+213
-36
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
321321
return true;
322322
}
323323

324+
bool VisitCleanupAttr(CleanupAttr *attr) {
325+
report(attr->getLocation(), attr->getFunctionDecl());
326+
return true;
327+
}
328+
324329
// TypeLoc visitors.
325330
void reportType(SourceLocation RefLoc, NamedDecl *ND) {
326331
// Reporting explicit references to types nested inside classes can cause

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,11 @@ TEST(WalkAST, OperatorNewDelete) {
570570
testWalk("struct A { static void $ambiguous^operator delete(void*); };",
571571
"void foo() { A a; ^delete &a; }");
572572
}
573+
574+
TEST(WalkAST, CleanupAttr) {
575+
testWalk("void* $explicit^freep(void *p);",
576+
"void foo() { __attribute__((^__cleanup__(freep))) char* x = 0; }");
577+
}
578+
573579
} // namespace
574580
} // namespace clang::include_cleaner

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
22492249
return Dependence::BackwardVectorizable;
22502250
}
22512251

2252-
bool MemoryDepChecker::areDepsSafe(const DepCandidates &AccessSets,
2252+
bool MemoryDepChecker::areDepsSafe(const DepCandidates &DepCands,
22532253
const MemAccessInfoList &CheckDeps) {
22542254

22552255
MinDepDistBytes = -1;
@@ -2260,9 +2260,9 @@ bool MemoryDepChecker::areDepsSafe(const DepCandidates &AccessSets,
22602260

22612261
// Check accesses within this set.
22622262
EquivalenceClasses<MemAccessInfo>::member_iterator AI =
2263-
AccessSets.findLeader(CurAccess);
2263+
DepCands.findLeader(CurAccess);
22642264
EquivalenceClasses<MemAccessInfo>::member_iterator AE =
2265-
AccessSets.member_end();
2265+
DepCands.member_end();
22662266

22672267
// Check every access pair.
22682268
while (AI != AE) {
@@ -2527,9 +2527,8 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
25272527
return true;
25282528
}
25292529

2530-
MemoryDepChecker::DepCandidates DependentAccesses;
2531-
AccessAnalysis Accesses(TheLoop, AA, LI, DependentAccesses, *PSE,
2532-
LoopAliasScopes);
2530+
MemoryDepChecker::DepCandidates DepCands;
2531+
AccessAnalysis Accesses(TheLoop, AA, LI, DepCands, *PSE, LoopAliasScopes);
25332532

25342533
// Holds the analyzed pointers. We don't want to call getUnderlyingObjects
25352534
// multiple times on the same object. If the ptr is accessed twice, once
@@ -2651,8 +2650,8 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
26512650
bool DepsAreSafe = true;
26522651
if (Accesses.isDependencyCheckNeeded()) {
26532652
LLVM_DEBUG(dbgs() << "LAA: Checking memory dependencies\n");
2654-
DepsAreSafe = DepChecker->areDepsSafe(DependentAccesses,
2655-
Accesses.getDependenciesToCheck());
2653+
DepsAreSafe =
2654+
DepChecker->areDepsSafe(DepCands, Accesses.getDependenciesToCheck());
26562655

26572656
if (!DepsAreSafe && DepChecker->shouldRetryWithRuntimeCheck()) {
26582657
LLVM_DEBUG(dbgs() << "LAA: Retrying with memory checks\n");

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,10 @@ void ComplexDeinterleavingGraph::identifyReductionNodes() {
17341734
if (Processed[i] || Real->getNumOperands() < 2)
17351735
continue;
17361736

1737+
// Can only combined integer reductions at the moment.
1738+
if (!ReductionInfo[Real].second->getType()->isIntegerTy())
1739+
continue;
1740+
17371741
RealPHI = ReductionInfo[Real].first;
17381742
ImagPHI = nullptr;
17391743
PHIsFound = false;

llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,24 @@ unsigned GISelValueTracking::computeNumSignBits(Register R,
836836
return TyBits - 1; // Every always-zero bit is a sign bit.
837837
break;
838838
}
839+
case TargetOpcode::G_BUILD_VECTOR: {
840+
// Collect the known bits that are shared by every demanded vector element.
841+
FirstAnswer = TyBits;
842+
APInt SingleDemandedElt(1, 1);
843+
for (unsigned i = 0, e = MI.getNumOperands() - 1; i < e; ++i) {
844+
if (!DemandedElts[i])
845+
continue;
846+
847+
unsigned Tmp2 = computeNumSignBits(MI.getOperand(i + 1).getReg(),
848+
SingleDemandedElt, Depth + 1);
849+
FirstAnswer = std::min(FirstAnswer, Tmp2);
850+
851+
// If we don't know any bits, early out.
852+
if (FirstAnswer == 1)
853+
break;
854+
}
855+
break;
856+
}
839857
case TargetOpcode::G_INTRINSIC:
840858
case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
841859
case TargetOpcode::G_INTRINSIC_CONVERGENT:

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "VPlan.h"
1717
#include "VPlanCFG.h"
1818
#include "VPlanDominatorTree.h"
19+
#include "VPlanHelpers.h"
1920
#include "llvm/ADT/SmallPtrSet.h"
2021
#include "llvm/ADT/TypeSwitch.h"
2122

@@ -235,19 +236,25 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
235236
if (isa<VPPredInstPHIRecipe>(UI))
236237
continue;
237238

238-
// If the user is in the same block, check it comes after R in
239-
// the block.
240-
if (UserVPBB == VPBB) {
241-
if (RecipeNumbering[UI] < RecipeNumbering[&R]) {
242-
errs() << "Use before def!\n";
243-
return false;
244-
}
239+
// If the user is in the same block, check it comes after R in the
240+
// block.
241+
if (UI->getParent() == VPBB) {
242+
if (RecipeNumbering[UI] >= RecipeNumbering[&R])
243+
continue;
244+
} else {
245+
if (VPDT.dominates(VPBB, UI->getParent()))
246+
continue;
245247
}
246248

247-
if (!VPDT.dominates(VPBB, UserVPBB)) {
248-
errs() << "Use before def!\n";
249-
return false;
250-
}
249+
errs() << "Use before def!\n";
250+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
251+
VPSlotTracker Tracker(VPBB->getPlan());
252+
UI->print(errs(), " ", Tracker);
253+
errs() << "\n before\n";
254+
R.print(errs(), " ", Tracker);
255+
errs() << "\n";
256+
#endif
257+
return false;
251258
}
252259
}
253260
if (const auto *EVL = dyn_cast<VPInstruction>(&R)) {

llvm/test/CodeGen/AArch64/GlobalISel/postselectopt-dead-cc-defs-in-fcmp.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ body: |
130130
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
131131
%12:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
132132
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
133-
%12:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
133+
%13:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
134134
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
135-
%14:gpr32common = UBFMWri %12, 1, 31
135+
%14:gpr32common = UBFMWri %13, 1, 31
136136
%60:gpr32 = MOVi32imm 1
137137
%16:gpr32 = CSELWr %14, %60, 8, implicit $nzcv
138138
$w0 = COPY %16

llvm/test/CodeGen/AArch64/GlobalISel/postselectopt-dead-cc-defs.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ body: |
130130
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
131131
%12:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
132132
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
133-
%12:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
133+
%13:gpr32 = SUBSWrr %2, %26, implicit-def $nzcv
134134
FCMPSrr %3, %4, implicit-def $nzcv, implicit $fpcr
135-
%14:gpr32common = UBFMWri %12, 1, 31
135+
%14:gpr32common = UBFMWri %13, 1, 31
136136
%60:gpr32 = MOVi32imm 1
137137
%16:gpr32 = CSELWr %14, %60, 8, implicit $nzcv
138138
$w0 = COPY %16

llvm/test/CodeGen/AArch64/aarch64-dup-ext.ll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,14 @@ define <4 x i32> @nonsplat_shuffleinsert2(<4 x i16> %b, i16 %b0, i16 %b1, i16 %b
312312
; CHECK-GI-LABEL: nonsplat_shuffleinsert2:
313313
; CHECK-GI: // %bb.0: // %entry
314314
; CHECK-GI-NEXT: sxth w8, w0
315-
; CHECK-GI-NEXT: sshll v0.4s, v0.4h, #0
316-
; CHECK-GI-NEXT: mov v1.s[0], w8
317-
; CHECK-GI-NEXT: sxth w8, w1
318-
; CHECK-GI-NEXT: mov v1.s[1], w8
315+
; CHECK-GI-NEXT: sxth w9, w1
316+
; CHECK-GI-NEXT: fmov s1, w8
319317
; CHECK-GI-NEXT: sxth w8, w2
320-
; CHECK-GI-NEXT: mov v1.s[2], w8
318+
; CHECK-GI-NEXT: mov v1.h[1], w9
319+
; CHECK-GI-NEXT: mov v1.h[2], w8
321320
; CHECK-GI-NEXT: sxth w8, w3
322-
; CHECK-GI-NEXT: mov v1.s[3], w8
323-
; CHECK-GI-NEXT: mul v0.4s, v1.4s, v0.4s
321+
; CHECK-GI-NEXT: mov v1.h[3], w8
322+
; CHECK-GI-NEXT: smull v0.4s, v1.4h, v0.4h
324323
; CHECK-GI-NEXT: ret
325324
entry:
326325
%s0 = sext i16 %b0 to i32

llvm/test/CodeGen/AArch64/complex-deinterleaving-opt-crash.ll

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2"
55
target triple = "aarch64-arm-none-linux"
66

7-
; Ensure that a second reduction-like pattern doesn't override the first
8-
; We don't care what this IR produces, just that it produces something and doesn't cause a crash
7+
; Ensure that a second reduction-like pattern doesn't override the first.
98
define void @reprocessing_crash() #0 {
10-
; CHECK-LABEL: define void @reprocessing_crash
9+
; CHECK-LABEL: define void @reprocessing_crash(
10+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
11+
; CHECK-NEXT: [[ENTRY:.*]]:
12+
; CHECK-NEXT: [[TMP0:%.*]] = call <vscale x 4 x double> @llvm.vector.interleave2.nxv4f64(<vscale x 2 x double> zeroinitializer, <vscale x 2 x double> zeroinitializer)
13+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
14+
; CHECK: [[VECTOR_BODY]]:
15+
; CHECK-NEXT: [[TMP1:%.*]] = phi <vscale x 4 x double> [ [[TMP0]], %[[ENTRY]] ], [ [[TMP2:%.*]], %[[VECTOR_BODY]] ]
16+
; CHECK-NEXT: [[TMP2]] = fsub <vscale x 4 x double> [[TMP1]], zeroinitializer
17+
; CHECK-NEXT: br i1 false, label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]]
18+
; CHECK: [[MIDDLE_BLOCK]]:
19+
; CHECK-NEXT: [[TMP3:%.*]] = call { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.vector.deinterleave2.nxv4f64(<vscale x 4 x double> [[TMP2]])
20+
; CHECK-NEXT: [[TMP4:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP3]], 0
21+
; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd <vscale x 2 x double> [[TMP4]], zeroinitializer
22+
; CHECK-NEXT: [[TMP5:%.*]] = extractvalue { <vscale x 2 x double>, <vscale x 2 x double> } [[TMP3]], 1
23+
; CHECK-NEXT: [[BIN_RDX23:%.*]] = fadd <vscale x 2 x double> [[TMP5]], zeroinitializer
24+
; CHECK-NEXT: ret void
1125
;
1226
entry:
1327
br label %vector.body
@@ -28,8 +42,58 @@ middle.block: ; preds = %vector.body
2842
ret void
2943
}
3044

45+
; Make sure we don't crash on floating point single reductions. For now, they
46+
; should be left as-is.
47+
define double @test_fp_single_reduction(i1 %c) #2 {
48+
; CHECK-LABEL: define double @test_fp_single_reduction(
49+
; CHECK-SAME: i1 [[C:%.*]]) #[[ATTR1:[0-9]+]] {
50+
; CHECK-NEXT: [[ENTRY:.*]]:
51+
; CHECK-NEXT: [[TMP0:%.*]] = call <8 x double> @llvm.vector.interleave2.v8f64(<4 x double> zeroinitializer, <4 x double> zeroinitializer)
52+
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
53+
; CHECK: [[VECTOR_BODY]]:
54+
; CHECK-NEXT: [[VEC_PHI218:%.*]] = phi <4 x double> [ zeroinitializer, %[[ENTRY]] ], [ [[TMP2:%.*]], %[[VECTOR_BODY]] ]
55+
; CHECK-NEXT: [[TMP1:%.*]] = phi <8 x double> [ [[TMP0]], %[[ENTRY]] ], [ [[TMP3:%.*]], %[[VECTOR_BODY]] ]
56+
; CHECK-NEXT: [[STRIDED_VEC:%.*]] = shufflevector <8 x double> zeroinitializer, <8 x double> zeroinitializer, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
57+
; CHECK-NEXT: [[TMP2]] = fadd <4 x double> [[VEC_PHI218]], [[STRIDED_VEC]]
58+
; CHECK-NEXT: [[TMP3]] = fadd <8 x double> [[TMP1]], zeroinitializer
59+
; CHECK-NEXT: br i1 [[C]], label %[[EXIT:.*]], label %[[VECTOR_BODY]]
60+
; CHECK: [[EXIT]]:
61+
; CHECK-NEXT: [[TMP4:%.*]] = call { <4 x double>, <4 x double> } @llvm.vector.deinterleave2.v8f64(<8 x double> [[TMP3]])
62+
; CHECK-NEXT: [[TMP5:%.*]] = extractvalue { <4 x double>, <4 x double> } [[TMP4]], 0
63+
; CHECK-NEXT: [[TMP6:%.*]] = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP5]])
64+
; CHECK-NEXT: [[TMP7:%.*]] = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP2]])
65+
; CHECK-NEXT: [[TMP8:%.*]] = extractvalue { <4 x double>, <4 x double> } [[TMP4]], 1
66+
; CHECK-NEXT: [[TMP9:%.*]] = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP8]])
67+
; CHECK-NEXT: [[ADD_1:%.*]] = fadd double [[TMP6]], [[TMP7]]
68+
; CHECK-NEXT: [[ADD_2:%.*]] = fadd double [[ADD_1]], [[TMP9]]
69+
; CHECK-NEXT: ret double [[ADD_2]]
70+
;
71+
entry:
72+
br label %vector.body
73+
74+
vector.body:
75+
%vec.phi216 = phi <4 x double> [ zeroinitializer, %entry ], [ %2, %vector.body ]
76+
%vec.phi218 = phi <4 x double> [ zeroinitializer, %entry ], [ %1, %vector.body ]
77+
%vec.phi222 = phi <4 x double> [ zeroinitializer, %entry ], [ %3, %vector.body ]
78+
%strided.vec = shufflevector <8 x double> zeroinitializer, <8 x double> zeroinitializer, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
79+
%strided.vec223 = shufflevector <8 x double> zeroinitializer, <8 x double> zeroinitializer, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
80+
%1 = fadd <4 x double> %vec.phi218, %strided.vec
81+
%2 = fadd <4 x double> %vec.phi216, %strided.vec
82+
%3 = fadd <4 x double> %vec.phi222, %strided.vec223
83+
br i1 %c, label %exit, label %vector.body
84+
85+
exit:
86+
%4 = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> %2)
87+
%5 = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> %1)
88+
%6 = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> %3)
89+
%add.1 = fadd double %4, %5
90+
%add.2 = fadd double %add.1, %6
91+
ret double %add.2
92+
}
93+
3194
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
3295
declare { <vscale x 2 x double>, <vscale x 2 x double> } @llvm.vector.deinterleave2.nxv4f64(<vscale x 4 x double>) #1
3396

3497
attributes #0 = { "target-cpu"="neoverse-v1" }
3598
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
99+
attributes #2 = { "target-cpu"="apple-m1" }

0 commit comments

Comments
 (0)