Skip to content

Commit b302d05

Browse files
authored
merge main into amd-staging (llvm#2443)
2 parents c253546 + e122b06 commit b302d05

File tree

17 files changed

+1011
-300
lines changed

17 files changed

+1011
-300
lines changed

flang/test/Driver/prefer-vector-width.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
subroutine func
1010
end subroutine func
1111

12-
! CHECK-DEF-NOT: attributes #0 = { "prefer-vector-width"={{.*}} }
13-
! CHECK-NONE: attributes #0 = { "prefer-vector-width"="none" }
14-
! CHECK-128: attributes #0 = { "prefer-vector-width"="128" }
15-
! CHECK-256: attributes #0 = { "prefer-vector-width"="256" }
12+
! CHECK-DEF-NOT: attributes #0 = { "prefer-vector-width"={{.*}}
13+
! CHECK-NONE: attributes #0 = { "prefer-vector-width"="none"
14+
! CHECK-128: attributes #0 = { "prefer-vector-width"="128"
15+
! CHECK-256: attributes #0 = { "prefer-vector-width"="256"
1616
! CHECK-INVALID:error: invalid value 'xxx' in '-mprefer-vector-width=xxx'

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class MCAssembler {
7171

7272
SmallVector<const MCSymbol *, 0> Symbols;
7373

74+
mutable SmallVector<std::pair<SMLoc, std::string>, 0> PendingErrors;
75+
7476
MCDwarfLineTableParams LTParams;
7577

7678
/// The set of function symbols for which a .thumb_func directive has
@@ -230,6 +232,10 @@ class MCAssembler {
230232
uint64_t FSize) const;
231233

232234
void reportError(SMLoc L, const Twine &Msg) const;
235+
// Record pending errors during layout iteration, as they may go away once the
236+
// layout is finalized.
237+
void recordError(SMLoc L, const Twine &Msg) const;
238+
void flushPendingErrors() const;
233239

234240
void dump() const;
235241
};

llvm/lib/MC/MCAssembler.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
217217
auto &FF = cast<MCFillFragment>(F);
218218
int64_t NumValues = 0;
219219
if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
220-
reportError(FF.getLoc(), "expected assembly-time absolute expression");
220+
recordError(FF.getLoc(), "expected assembly-time absolute expression");
221221
return 0;
222222
}
223223
int64_t Size = NumValues * FF.getValueSize();
224224
if (Size < 0) {
225-
reportError(FF.getLoc(), "invalid number of bytes");
225+
recordError(FF.getLoc(), "invalid number of bytes");
226226
return 0;
227227
}
228228
return Size;
@@ -266,7 +266,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
266266
const MCOrgFragment &OF = cast<MCOrgFragment>(F);
267267
MCValue Value;
268268
if (!OF.getOffset().evaluateAsValue(Value, *this)) {
269-
reportError(OF.getLoc(), "expected assembly-time absolute expression");
269+
recordError(OF.getLoc(), "expected assembly-time absolute expression");
270270
return 0;
271271
}
272272

@@ -275,14 +275,14 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
275275
if (const auto *SA = Value.getAddSym()) {
276276
uint64_t Val;
277277
if (!getSymbolOffset(*SA, Val)) {
278-
reportError(OF.getLoc(), "expected absolute expression");
278+
recordError(OF.getLoc(), "expected absolute expression");
279279
return 0;
280280
}
281281
TargetLocation += Val;
282282
}
283283
int64_t Size = TargetLocation - FragmentOffset;
284284
if (Size < 0 || Size >= 0x40000000) {
285-
reportError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
285+
recordError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
286286
"' (at offset '" + Twine(FragmentOffset) +
287287
"')");
288288
return 0;
@@ -825,6 +825,7 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
825825
for (const MCFragment &F : *Sec)
826826
writeFragment(OS, *this, F);
827827

828+
flushPendingErrors();
828829
assert(getContext().hadError() ||
829830
OS.tell() - Start == getSectionAddressSize(*Sec));
830831
}
@@ -878,6 +879,8 @@ void MCAssembler::layout() {
878879
// Finalize the layout, including fragment lowering.
879880
getBackend().finishLayout(*this);
880881

882+
flushPendingErrors();
883+
881884
DEBUG_WITH_TYPE("mc-dump", {
882885
errs() << "assembler backend - final-layout\n--\n";
883886
dump(); });
@@ -968,6 +971,7 @@ void MCAssembler::Finish() {
968971
stats::ObjectBytes += getWriter().writeObject();
969972

970973
HasLayout = false;
974+
assert(PendingErrors.empty());
971975
}
972976

973977
bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
@@ -1222,6 +1226,7 @@ bool MCAssembler::relaxFragment(MCFragment &F) {
12221226

12231227
bool MCAssembler::layoutOnce() {
12241228
++stats::RelaxationSteps;
1229+
PendingErrors.clear();
12251230

12261231
bool Changed = false;
12271232
for (MCSection &Sec : *this)
@@ -1235,6 +1240,16 @@ void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
12351240
getContext().reportError(L, Msg);
12361241
}
12371242

1243+
void MCAssembler::recordError(SMLoc Loc, const Twine &Msg) const {
1244+
PendingErrors.emplace_back(Loc, Msg.str());
1245+
}
1246+
1247+
void MCAssembler::flushPendingErrors() const {
1248+
for (auto &Err : PendingErrors)
1249+
reportError(Err.first, Err.second);
1250+
PendingErrors.clear();
1251+
}
1252+
12381253
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
12391254
LLVM_DUMP_METHOD void MCAssembler::dump() const{
12401255
raw_ostream &OS = errs();

llvm/lib/MC/MCExpr.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,6 @@ bool MCExpr::evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const {
475475
bool MCExpr::evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const {
476476
return evaluateAsRelocatableImpl(Res, &Asm, true);
477477
}
478-
static bool canExpand(const MCSymbol &Sym, bool InSet) {
479-
if (Sym.isWeakExternal())
480-
return false;
481-
482-
if (InSet)
483-
return true;
484-
return !Sym.isInSection();
485-
}
486478

487479
bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
488480
bool InSet) const {
@@ -500,7 +492,10 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
500492
const auto Kind = SRE->getKind();
501493
bool Layout = Asm && Asm->hasLayout();
502494

503-
// Evaluate recursively if this is a variable.
495+
// If the symbol is equated, resolve the inner expression.
496+
// However, when two IMAGE_WEAK_EXTERN_ANTI_DEPENDENCY symbols reference
497+
// each other, we retain the equated symbol to avoid a cyclic definition
498+
// error.
504499
if (Sym.isResolving()) {
505500
if (Asm && Asm->hasFinalLayout()) {
506501
Asm->getContext().reportError(
@@ -511,13 +506,20 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
511506
return false;
512507
}
513508
if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
514-
canExpand(Sym, InSet)) {
509+
!Sym.isWeakExternal()) {
515510
Sym.setIsResolving(true);
516511
auto _ = make_scope_exit([&] { Sym.setIsResolving(false); });
517512
bool IsMachO =
518513
Asm && Asm->getContext().getAsmInfo()->hasSubsectionsViaSymbols();
519-
if (Sym.getVariableValue()->evaluateAsRelocatableImpl(Res, Asm,
520-
InSet || IsMachO)) {
514+
if (!Sym.getVariableValue()->evaluateAsRelocatableImpl(Res, Asm,
515+
InSet || IsMachO))
516+
return false;
517+
// When generating relocations, if Sym resolves to a symbol relative to a
518+
// section, relocations are generated against Sym. Treat label differences
519+
// as constants.
520+
auto *A = Res.getAddSym();
521+
auto *B = Res.getSubSym();
522+
if (InSet || !(A && !B && A->isInSection())) {
521523
if (Kind != MCSymbolRefExpr::VK_None) {
522524
if (Res.isAbsolute()) {
523525
Res = MCValue::get(&Sym, nullptr, 0, Kind);
@@ -534,8 +536,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
534536
if (!IsMachO)
535537
return true;
536538

537-
auto *A = Res.getAddSym();
538-
auto *B = Res.getSubSym();
539539
// FIXME: This is small hack. Given
540540
// a = b + 4
541541
// .long a
@@ -548,8 +548,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
548548
// Allows aliases with zero offset.
549549
if (Res.getConstant() == 0 && (!A || !B))
550550
return true;
551-
} else {
552-
return false;
553551
}
554552
}
555553

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6438,6 +6438,11 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
64386438
return Parser.TokError("missing expression");
64396439
if (Parser.parseEOL())
64406440
return true;
6441+
// Relocation specifiers are not permitted. For now, handle just
6442+
// MCSymbolRefExpr.
6443+
if (auto *S = dyn_cast<MCSymbolRefExpr>(Value); S && S->getSpecifier())
6444+
return Parser.Error(
6445+
EqualLoc, "relocation specifier not permitted in symbol equating");
64416446

64426447
// Validate that the LHS is allowed to be a variable (either it has not been
64436448
// used as a symbol, or it is an absolute symbol).

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,6 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
916916
continue;
917917
}
918918

919-
#ifndef NDEBUG
920-
const uint64_t OrigOffset = Asm.getFragmentOffset(F);
921-
#endif
922919
const uint64_t OrigSize = Asm.computeFragmentSize(F);
923920

924921
// To keep the effects local, prefer to relax instructions closest to
@@ -949,14 +946,6 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
949946
if (F.getKind() == MCFragment::FT_BoundaryAlign)
950947
cast<MCBoundaryAlignFragment>(F).setSize(RemainingSize);
951948

952-
#ifndef NDEBUG
953-
const uint64_t FinalOffset = Asm.getFragmentOffset(F);
954-
const uint64_t FinalSize = Asm.computeFragmentSize(F);
955-
assert(OrigOffset + OrigSize == FinalOffset + FinalSize &&
956-
"can't move start of next fragment!");
957-
assert(FinalSize == RemainingSize && "inconsistent size computation?");
958-
#endif
959-
960949
// If we're looking at a boundary align, make sure we don't try to pad
961950
// its target instructions for some following directive. Doing so would
962951
// break the alignment of the current boundary align.
@@ -971,10 +960,8 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm) const {
971960
}
972961

973962
// The layout is done. Mark every fragment as valid.
974-
for (MCSection &Section : Asm) {
963+
for (MCSection &Section : Asm)
975964
Asm.getFragmentOffset(*Section.curFragList()->Tail);
976-
Asm.computeFragmentSize(*Section.curFragList()->Tail);
977-
}
978965
}
979966

980967
unsigned X86AsmBackend::getMaximumNopSize(const MCSubtargetInfo &STI) const {

llvm/test/Analysis/LoopAccessAnalysis/no-dep-via-loop-guards.ll

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,90 @@ loop:
349349
exit:
350350
ret void
351351
}
352+
353+
; TODO Should be able to determine no-dep, same as @nodep_via_logical_and_2.
354+
define void @nodep_via_logical_and_1(ptr %A, i32 %index, i32 %n) {
355+
; CHECK-LABEL: 'nodep_via_logical_and_1'
356+
; CHECK-NEXT: loop:
357+
; CHECK-NEXT: Report: unsafe dependent memory operations in loop. Use #pragma clang loop distribute(enable) to allow loop distribution to attempt to isolate the offending operations into a separate loop
358+
; CHECK-NEXT: Unknown data dependence.
359+
; CHECK-NEXT: Dependences:
360+
; CHECK-NEXT: Unknown:
361+
; CHECK-NEXT: %0 = load double, ptr %gep.load, align 8 ->
362+
; CHECK-NEXT: store double %0, ptr %gep.store, align 8
363+
; CHECK-EMPTY:
364+
; CHECK-NEXT: Run-time memory checks:
365+
; CHECK-NEXT: Grouped accesses:
366+
; CHECK-EMPTY:
367+
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
368+
; CHECK-NEXT: SCEV assumptions:
369+
; CHECK-EMPTY:
370+
; CHECK-NEXT: Expressions re-written:
371+
;
372+
entry:
373+
%pre.0 = icmp sgt i32 %index, 0
374+
%pre.1 = icmp slt i32 %index, %n
375+
%and.pre = select i1 %pre.1, i1 %pre.0, i1 false
376+
br i1 %and.pre, label %ph, label %exit
377+
378+
ph:
379+
%idx.1 = add i32 %index, 1
380+
%start = zext i32 %idx.1 to i64
381+
br label %loop
382+
383+
loop:
384+
%iv = phi i64 [ %start, %ph ], [ %iv.next, %loop ]
385+
%gep.load = getelementptr double, ptr %A, i64 %iv
386+
%1 = load double, ptr %gep.load, align 8
387+
%index.ext = zext i32 %index to i64
388+
%gep.store = getelementptr double, ptr %A, i64 %index.ext
389+
store double %1, ptr %gep.store, align 8
390+
%iv.next = add i64 %iv, 1
391+
%t = trunc i64 %iv to i32
392+
%ec = icmp slt i32 %t, 1
393+
br i1 %ec, label %loop, label %exit
394+
395+
exit:
396+
ret void
397+
}
398+
399+
; Same as nodep_via_logical_and_1 but with different operand order of the logical and.
400+
define void @nodep_via_logical_and_2(ptr %A, i32 %index, i32 %n) {
401+
; CHECK-LABEL: 'nodep_via_logical_and_2'
402+
; CHECK-NEXT: loop:
403+
; CHECK-NEXT: Memory dependences are safe
404+
; CHECK-NEXT: Dependences:
405+
; CHECK-NEXT: Run-time memory checks:
406+
; CHECK-NEXT: Grouped accesses:
407+
; CHECK-EMPTY:
408+
; CHECK-NEXT: Non vectorizable stores to invariant address were not found in loop.
409+
; CHECK-NEXT: SCEV assumptions:
410+
; CHECK-EMPTY:
411+
; CHECK-NEXT: Expressions re-written:
412+
;
413+
entry:
414+
%pre.0 = icmp sgt i32 %index, 0
415+
%pre.1 = icmp slt i32 %index, %n
416+
%and.pre = select i1 %pre.0, i1 %pre.1, i1 false
417+
br i1 %and.pre, label %ph, label %exit
418+
419+
ph:
420+
%idx.1 = add i32 %index, 1
421+
%start = zext i32 %idx.1 to i64
422+
br label %loop
423+
424+
loop:
425+
%iv = phi i64 [ %start, %ph ], [ %iv.next, %loop ]
426+
%gep.load = getelementptr double, ptr %A, i64 %iv
427+
%1 = load double, ptr %gep.load, align 8
428+
%index.ext = zext i32 %index to i64
429+
%gep.store = getelementptr double, ptr %A, i64 %index.ext
430+
store double %1, ptr %gep.store, align 8
431+
%iv.next = add i64 %iv, 1
432+
%t = trunc i64 %iv to i32
433+
%ec = icmp slt i32 %t, 1
434+
br i1 %ec, label %loop, label %exit
435+
436+
exit:
437+
ret void
438+
}

0 commit comments

Comments
 (0)