Skip to content

Commit 09ac879

Browse files
ronliebskganesan008
authored andcommitted
merge main into amd-staging
2 parents b343c3e + 461be1d commit 09ac879

File tree

15 files changed

+229
-36
lines changed

15 files changed

+229
-36
lines changed

clang/include/clang/AST/Redeclarable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class Redeclarable {
114114

115115
bool isFirst() const {
116116
return isa<KnownLatest>(Link) ||
117-
// FIXME: 'template' is required on the next line due to an
118-
// apparent clang bug.
119117
isa<UninitializedLatest>(cast<NotKnownLatest>(Link));
120118
}
121119

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct Descriptor final {
274274

275275
void dump() const;
276276
void dump(llvm::raw_ostream &OS) const;
277+
void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const;
277278
};
278279

279280
/// Bitfield tracking the initialisation status of elements of primitive arrays.

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const {
251251
OS << " dummy";
252252
}
253253

254+
/// Dump descriptor, including all valid offsets.
255+
LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset,
256+
unsigned Indent) const {
257+
unsigned Spaces = Indent * 2;
258+
llvm::raw_ostream &OS = llvm::errs();
259+
OS.indent(Spaces);
260+
dump(OS);
261+
OS << '\n';
262+
OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n";
263+
OS.indent(Spaces) << "Size: " << getSize() << " bytes\n";
264+
OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n";
265+
Offset += getMetadataSize();
266+
if (isCompositeArray()) {
267+
OS.indent(Spaces) << "Elements: " << getNumElems() << '\n';
268+
unsigned FO = Offset;
269+
for (unsigned I = 0; I != getNumElems(); ++I) {
270+
FO += sizeof(InlineDescriptor);
271+
assert(ElemDesc->getMetadataSize() == 0);
272+
OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n';
273+
ElemDesc->dumpFull(FO, Indent + 1);
274+
275+
FO += ElemDesc->getAllocSize();
276+
}
277+
} else if (isRecord()) {
278+
ElemRecord->dump(OS, Indent + 1, Offset);
279+
} else if (isPrimitive()) {
280+
} else {
281+
}
282+
283+
OS << '\n';
284+
}
285+
254286
LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const {
255287
{
256288
ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});

clang/lib/AST/ByteCode/DynamicAllocator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Block *DynamicAllocator::allocate(const Expr *Source, PrimType T,
5454
Block *DynamicAllocator::allocate(const Descriptor *ElementDesc,
5555
size_t NumElements, unsigned EvalID,
5656
Form AllocForm) {
57+
assert(ElementDesc->getMetadataSize() == 0);
5758
// Create a new descriptor for an array of the specified size and
5859
// element type.
5960
const Descriptor *D = allocateDescriptor(
@@ -72,6 +73,7 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID,
7273
auto *B = new (Memory.get()) Block(EvalID, D, /*isStatic=*/false);
7374
B->invokeCtor();
7475

76+
assert(D->getMetadataSize() == sizeof(InlineDescriptor));
7577
InlineDescriptor *ID = reinterpret_cast<InlineDescriptor *>(B->rawData());
7678
ID->Desc = D;
7779
ID->IsActive = true;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,9 +2896,7 @@ inline bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
28962896
Block *B = Allocator.allocate(Desc, S.Ctx.getEvalID(),
28972897
DynamicAllocator::Form::NonArray);
28982898
assert(B);
2899-
29002899
S.Stk.push<Pointer>(B);
2901-
29022900
return true;
29032901
}
29042902

@@ -2923,8 +2921,7 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source,
29232921
Allocator.allocate(Source, T, static_cast<size_t>(NumElements),
29242922
S.Ctx.getEvalID(), DynamicAllocator::Form::Array);
29252923
assert(B);
2926-
S.Stk.push<Pointer>(B, sizeof(InlineDescriptor));
2927-
2924+
S.Stk.push<Pointer>(B);
29282925
return true;
29292926
}
29302927

@@ -2950,9 +2947,7 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc,
29502947
Allocator.allocate(ElementDesc, static_cast<size_t>(NumElements),
29512948
S.Ctx.getEvalID(), DynamicAllocator::Form::Array);
29522949
assert(B);
2953-
2954-
S.Stk.push<Pointer>(B, sizeof(InlineDescriptor));
2955-
2950+
S.Stk.push<Pointer>(B);
29562951
return true;
29572952
}
29582953

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,49 +1655,50 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
16551655
return false;
16561656
}
16571657

1658+
bool IsArray = NumElems.ugt(1);
16581659
std::optional<PrimType> ElemT = S.getContext().classify(ElemType);
16591660
DynamicAllocator &Allocator = S.getAllocator();
16601661
if (ElemT) {
1661-
if (NumElems.ule(1)) {
1662-
const Descriptor *Desc =
1663-
S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD,
1664-
/*IsConst=*/false, /*IsTemporary=*/false,
1665-
/*IsMutable=*/false);
1666-
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1662+
if (IsArray) {
1663+
Block *B = Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(),
1664+
S.Ctx.getEvalID(),
16671665
DynamicAllocator::Form::Operator);
16681666
assert(B);
1669-
1670-
S.Stk.push<Pointer>(B);
1667+
S.Stk.push<Pointer>(Pointer(B).atIndex(0));
16711668
return true;
16721669
}
1673-
assert(NumElems.ugt(1));
16741670

1675-
Block *B =
1676-
Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(),
1677-
S.Ctx.getEvalID(), DynamicAllocator::Form::Operator);
1671+
const Descriptor *Desc =
1672+
S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD,
1673+
/*IsConst=*/false, /*IsTemporary=*/false,
1674+
/*IsMutable=*/false);
1675+
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1676+
DynamicAllocator::Form::Operator);
16781677
assert(B);
1678+
16791679
S.Stk.push<Pointer>(B);
16801680
return true;
16811681
}
16821682

16831683
assert(!ElemT);
16841684
// Structs etc.
16851685
const Descriptor *Desc = S.P.createDescriptor(
1686-
NewCall, ElemType.getTypePtr(), Descriptor::InlineDescMD,
1686+
NewCall, ElemType.getTypePtr(),
1687+
IsArray ? std::nullopt : Descriptor::InlineDescMD,
16871688
/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false,
16881689
/*Init=*/nullptr);
16891690

1690-
if (NumElems.ule(1)) {
1691-
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1692-
DynamicAllocator::Form::Operator);
1691+
if (IsArray) {
1692+
Block *B =
1693+
Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(),
1694+
DynamicAllocator::Form::Operator);
16931695
assert(B);
1694-
S.Stk.push<Pointer>(B);
1696+
S.Stk.push<Pointer>(Pointer(B).atIndex(0));
16951697
return true;
16961698
}
16971699

1698-
Block *B =
1699-
Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(),
1700-
DynamicAllocator::Form::Operator);
1700+
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1701+
DynamicAllocator::Form::Operator);
17011702
assert(B);
17021703
S.Stk.push<Pointer>(B);
17031704
return true;

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
432432
return allocateDescriptor(D, *T, MDSize, IsTemporary,
433433
Descriptor::UnknownSize{});
434434
} else {
435-
const Descriptor *Desc = createDescriptor(D, ElemTy.getTypePtr(),
436-
MDSize, IsConst, IsTemporary);
435+
const Descriptor *Desc = createDescriptor(
436+
D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
437437
if (!Desc)
438438
return nullptr;
439439
return allocateDescriptor(D, Desc, MDSize, IsTemporary,

clang/lib/Headers/amxavx512intrin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
/// dst.byte[i] := a.row[row_index].byte[row_chunk+i]
229229
/// ENDFOR
230230
/// \endcode
231-
#define _tile_movrow(a, b) __builtin_ia32_tilemovrow(a, b)
231+
#define _tile_movrow(a, b) ((__m512i)__builtin_ia32_tilemovrow(a, b))
232232

233233
/// This is internal intrinsic. C/C++ user should avoid calling it directly.
234234

clang/lib/Headers/shaintrin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
/// An immediate value where bits [1:0] select among four possible
4848
/// combining functions and rounding constants (not specified here).
4949
/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1 state.
50-
#define _mm_sha1rnds4_epu32(V1, V2, M) \
51-
__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), (__v4si)(__m128i)(V2), (M))
50+
#define _mm_sha1rnds4_epu32(V1, V2, M) \
51+
((__m128i)__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), \
52+
(__v4si)(__m128i)(V2), (M)))
5253

5354
/// Calculates the SHA-1 state variable E from the SHA-1 state variables in
5455
/// the 128-bit vector of [4 x i32] in \a __X, adds that to the next set of
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
2+
// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s
3+
4+
5+
/// This example used to cause an invalid read because allocating
6+
/// an array needs to return a pointer to the first element,
7+
/// not to the array.
8+
9+
namespace std {
10+
using size_t = decltype(sizeof(0));
11+
12+
template <class _Tp>
13+
class allocator {
14+
public:
15+
typedef size_t size_type;
16+
typedef _Tp value_type;
17+
constexpr _Tp *allocate(size_t __n) {
18+
return static_cast<_Tp *>(::operator new(__n * sizeof(_Tp)));
19+
}
20+
};
21+
}
22+
23+
void *operator new(std::size_t, void *p) { return p; }
24+
void* operator new[] (std::size_t, void* p) {return p;}
25+
26+
namespace std {
27+
template <class _Ep>
28+
class initializer_list {
29+
const _Ep *__begin_;
30+
__SIZE_TYPE__ __size_;
31+
32+
public:
33+
typedef _Ep value_type;
34+
typedef const _Ep &reference;
35+
constexpr __SIZE_TYPE__ size() const noexcept { return __size_; }
36+
constexpr const _Ep *begin() const noexcept { return __begin_; }
37+
constexpr const _Ep *end() const noexcept { return __begin_ + __size_; }
38+
};
39+
}
40+
41+
template<typename T>
42+
class vector {
43+
public:
44+
constexpr vector(std::initializer_list<T> Ts) {
45+
A = B = std::allocator<T>{}.allocate(Ts.size()); // both-note {{heap allocation performed here}}
46+
47+
new (A) T(*Ts.begin());
48+
}
49+
private:
50+
T *A = nullptr;
51+
T *B = nullptr;
52+
};
53+
54+
constexpr vector<vector<int>> ints = {{3}, {4}}; // both-error {{must be initialized by a constant expression}} \
55+
// both-note {{pointer to}}

clang/test/CodeGen/X86/amxavx512-builtins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-tile -target-feature +amx-avx512 \
2-
// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression | FileCheck %s
2+
// RUN: -target-feature +avx10.2-512 -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression -flax-vector-conversions=none | FileCheck %s
33

44
#include <immintrin.h>
55
#include <stddef.h>

clang/test/CodeGen/X86/sha-builtins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -o - | FileCheck %s
1+
// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-unknown-unknown -target-feature +sha -emit-llvm -flax-vector-conversions=none -o - | FileCheck %s
22

33

44
#include <immintrin.h>

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,6 +5637,11 @@ Instruction *InstCombinerImpl::foldICmpWithMinMax(Instruction &I,
56375637
return false;
56385638
return std::nullopt;
56395639
};
5640+
// Remove samesign here since it is illegal to keep it when we speculatively
5641+
// execute comparisons. For example, `icmp samesign ult umax(X, -46), -32`
5642+
// cannot be decomposed into `(icmp samesign ult X, -46) or (icmp samesign ult
5643+
// -46, -32)`. `X` is allowed to be non-negative here.
5644+
Pred = static_cast<CmpInst::Predicate>(Pred);
56405645
auto CmpXZ = IsCondKnownTrue(simplifyICmpInst(Pred, X, Z, Q));
56415646
auto CmpYZ = IsCondKnownTrue(simplifyICmpInst(Pred, Y, Z, Q));
56425647
if (!CmpXZ.has_value() && !CmpYZ.has_value())

llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,3 +1731,82 @@ define i8 @select_icmp_eq_and_1_0_lshr_tv(i8 %x, i8 %y) {
17311731
%select = select i1 %cmp, i8 %blshr, i8 %y
17321732
ret i8 %select
17331733
}
1734+
1735+
define i8 @select_trunc_or_2(i8 %x, i8 %y) {
1736+
; CHECK-LABEL: @select_trunc_or_2(
1737+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
1738+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
1739+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[OR]], i8 [[Y]]
1740+
; CHECK-NEXT: ret i8 [[SELECT]]
1741+
;
1742+
%trunc = trunc i8 %x to i1
1743+
%or = or i8 %y, 2
1744+
%select = select i1 %trunc, i8 %or, i8 %y
1745+
ret i8 %select
1746+
}
1747+
1748+
define i8 @select_not_trunc_or_2(i8 %x, i8 %y) {
1749+
; CHECK-LABEL: @select_not_trunc_or_2(
1750+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
1751+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
1752+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[OR]], i8 [[Y]]
1753+
; CHECK-NEXT: ret i8 [[SELECT]]
1754+
;
1755+
%trunc = trunc i8 %x to i1
1756+
%not = xor i1 %trunc, true
1757+
%or = or i8 %y, 2
1758+
%select = select i1 %not, i8 %y, i8 %or
1759+
ret i8 %select
1760+
}
1761+
1762+
define i8 @select_trunc_nuw_or_2(i8 %x, i8 %y) {
1763+
; CHECK-LABEL: @select_trunc_nuw_or_2(
1764+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i8 [[X:%.*]] to i1
1765+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
1766+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[OR]], i8 [[Y]]
1767+
; CHECK-NEXT: ret i8 [[SELECT]]
1768+
;
1769+
%trunc = trunc nuw i8 %x to i1
1770+
%or = or i8 %y, 2
1771+
%select = select i1 %trunc, i8 %or, i8 %y
1772+
ret i8 %select
1773+
}
1774+
1775+
define i8 @select_trunc_nsw_or_2(i8 %x, i8 %y) {
1776+
; CHECK-LABEL: @select_trunc_nsw_or_2(
1777+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nsw i8 [[X:%.*]] to i1
1778+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
1779+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[OR]], i8 [[Y]]
1780+
; CHECK-NEXT: ret i8 [[SELECT]]
1781+
;
1782+
%trunc = trunc nsw i8 %x to i1
1783+
%or = or i8 %y, 2
1784+
%select = select i1 %trunc, i8 %or, i8 %y
1785+
ret i8 %select
1786+
}
1787+
1788+
define <2 x i8> @select_trunc_or_2_vec(<2 x i8> %x, <2 x i8> %y) {
1789+
; CHECK-LABEL: @select_trunc_or_2_vec(
1790+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc <2 x i8> [[X:%.*]] to <2 x i1>
1791+
; CHECK-NEXT: [[OR:%.*]] = or <2 x i8> [[Y:%.*]], splat (i8 2)
1792+
; CHECK-NEXT: [[SELECT:%.*]] = select <2 x i1> [[TRUNC]], <2 x i8> [[OR]], <2 x i8> [[Y]]
1793+
; CHECK-NEXT: ret <2 x i8> [[SELECT]]
1794+
;
1795+
%trunc = trunc <2 x i8> %x to <2 x i1>
1796+
%or = or <2 x i8> %y, <i8 2, i8 2>
1797+
%select = select <2 x i1> %trunc, <2 x i8> %or, <2 x i8> %y
1798+
ret <2 x i8> %select
1799+
}
1800+
1801+
define i8 @neg_select_trunc_or_2(i8 %x, i8 %y) {
1802+
; CHECK-LABEL: @neg_select_trunc_or_2(
1803+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
1804+
; CHECK-NEXT: [[OR:%.*]] = or i8 [[Y:%.*]], 2
1805+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i8 [[Y]], i8 [[OR]]
1806+
; CHECK-NEXT: ret i8 [[SELECT]]
1807+
;
1808+
%trunc = trunc i8 %x to i1
1809+
%or = or i8 %y, 2
1810+
%select = select i1 %trunc, i8 %y, i8 %or
1811+
ret i8 %select
1812+
}

llvm/test/Transforms/InstCombine/umax-icmp.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,4 +804,28 @@ end:
804804
ret void
805805
}
806806

807+
define i1 @pr126974(i8 %x) {
808+
; CHECK-LABEL: @pr126974(
809+
; CHECK-NEXT: entry:
810+
; CHECK-NEXT: [[COND:%.*]] = icmp sgt i8 [[X:%.*]], -2
811+
; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
812+
; CHECK: if.then:
813+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], -1
814+
; CHECK-NEXT: ret i1 [[CMP]]
815+
; CHECK: if.else:
816+
; CHECK-NEXT: ret i1 false
817+
;
818+
entry:
819+
%cond = icmp sgt i8 %x, -2
820+
br i1 %cond, label %if.then, label %if.else
821+
822+
if.then:
823+
%umax = call i8 @llvm.umax.i8(i8 %x, i8 -46)
824+
%cmp = icmp samesign ult i8 %umax, -32
825+
ret i1 %cmp
826+
827+
if.else:
828+
ret i1 false
829+
}
830+
807831
declare i32 @llvm.umax.i32(i32, i32)

0 commit comments

Comments
 (0)