Skip to content

Commit 0780ee5

Browse files
authored
Merge branch 'main' into issue_165752
2 parents 8b4ebdc + 863730f commit 0780ee5

File tree

157 files changed

+1096
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+1096
-855
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ let Features = "sse3", Attributes = [NoThrow, RequiredVectorWidth<128>] in {
311311
def lddqu : X86Builtin<"_Vector<16, char>(char const *)">;
312312
}
313313

314-
let Features = "ssse3", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
314+
let Features = "ssse3", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
315315
def palignr128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>, _Constant int)">;
316316
}
317317

@@ -605,8 +605,7 @@ let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWid
605605

606606
let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
607607
def mpsadbw256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Constant char)">;
608-
def palignr256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, "
609-
"_Vector<32, char>, _Constant int)">;
608+
610609
def psadbw256
611610
: X86Builtin<
612611
"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
@@ -630,6 +629,7 @@ let Features = "avx2", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWi
630629
def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
631630
def pavgb256 : X86Builtin<"_Vector<32, unsigned char>(_Vector<32, unsigned char>, _Vector<32, unsigned char>)">;
632631
def pavgw256 : X86Builtin<"_Vector<16, unsigned short>(_Vector<16, unsigned short>, _Vector<16, unsigned short>)">;
632+
def palignr256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Constant int)">;
633633

634634
def pblendd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>, _Constant int)">;
635635
def pblendd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>, _Constant int)">;
@@ -3263,7 +3263,7 @@ let Features = "avx512bw", Attributes = [NoThrow, Const] in {
32633263
def kmovq : X86Builtin<"unsigned long long int(unsigned long long int)">;
32643264
}
32653265

3266-
let Features = "avx512bw", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
3266+
let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
32673267
def palignr512 : X86Builtin<"_Vector<64, char>(_Vector<64, char>, _Vector<64, char>, _Constant int)">;
32683268
}
32693269

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,6 +4754,30 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
47544754
return APInt(8, 0);
47554755
});
47564756

4757+
case X86::BI__builtin_ia32_palignr128:
4758+
case X86::BI__builtin_ia32_palignr256:
4759+
case X86::BI__builtin_ia32_palignr512:
4760+
return interp__builtin_ia32_shuffle_generic(
4761+
S, OpPC, Call, [](unsigned DstIdx, unsigned Shift) {
4762+
// Default to -1 → zero-fill this destination element
4763+
unsigned VecIdx = 1;
4764+
int ElemIdx = -1;
4765+
4766+
int Lane = DstIdx / 16;
4767+
int Offset = DstIdx % 16;
4768+
4769+
// Elements come from VecB first, then VecA after the shift boundary
4770+
unsigned ShiftedIdx = Offset + (Shift & 0xFF);
4771+
if (ShiftedIdx < 16) { // from VecB
4772+
ElemIdx = ShiftedIdx + (Lane * 16);
4773+
} else if (ShiftedIdx < 32) { // from VecA
4774+
VecIdx = 0;
4775+
ElemIdx = (ShiftedIdx - 16) + (Lane * 16);
4776+
}
4777+
4778+
return std::pair<unsigned, int>{VecIdx, ElemIdx};
4779+
});
4780+
47574781
default:
47584782
S.FFDiag(S.Current->getLocation(OpPC),
47594783
diag::note_invalid_subexpr_in_const_expr)

clang/lib/AST/ExprConstant.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12124,8 +12124,17 @@ static bool evalShuffleGeneric(
1212412124
if (SrcIdx < 0) {
1212512125
// Zero out this element
1212612126
QualType ElemTy = VT->getElementType();
12127-
ResultElements.push_back(
12128-
APValue(APFloat::getZero(Info.Ctx.getFloatTypeSemantics(ElemTy))));
12127+
if (ElemTy->isRealFloatingType()) {
12128+
ResultElements.push_back(
12129+
APValue(APFloat::getZero(Info.Ctx.getFloatTypeSemantics(ElemTy))));
12130+
} else if (ElemTy->isIntegerType()) {
12131+
APValue Zero(Info.Ctx.MakeIntValue(0, ElemTy));
12132+
ResultElements.push_back(APValue(Zero));
12133+
} else {
12134+
// Other types of fallback logic
12135+
ResultElements.push_back(APValue());
12136+
}
12137+
1212912138
} else {
1213012139
const APValue &Src = (SrcVecIdx == 0) ? A : B;
1213112140
ResultElements.push_back(Src.getVectorElt(SrcIdx));
@@ -13556,6 +13565,33 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1355613565

1355713566
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1355813567
}
13568+
13569+
case X86::BI__builtin_ia32_palignr128:
13570+
case X86::BI__builtin_ia32_palignr256:
13571+
case X86::BI__builtin_ia32_palignr512: {
13572+
APValue R;
13573+
if (!evalShuffleGeneric(Info, E, R, [](unsigned DstIdx, unsigned Shift) {
13574+
// Default to -1 → zero-fill this destination element
13575+
unsigned VecIdx = 1;
13576+
int ElemIdx = -1;
13577+
13578+
int Lane = DstIdx / 16;
13579+
int Offset = DstIdx % 16;
13580+
13581+
// Elements come from VecB first, then VecA after the shift boundary
13582+
unsigned ShiftedIdx = Offset + (Shift & 0xFF);
13583+
if (ShiftedIdx < 16) { // from VecB
13584+
ElemIdx = ShiftedIdx + (Lane * 16);
13585+
} else if (ShiftedIdx < 32) { // from VecA
13586+
VecIdx = 0;
13587+
ElemIdx = (ShiftedIdx - 16) + (Lane * 16);
13588+
}
13589+
13590+
return std::pair<unsigned, int>{VecIdx, ElemIdx};
13591+
}))
13592+
return false;
13593+
return Success(R, E);
13594+
}
1355913595
case X86::BI__builtin_ia32_vpermi2varq128:
1356013596
case X86::BI__builtin_ia32_vpermi2varpd128: {
1356113597
APValue R;

clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
using namespace mlir;
2727
using namespace cir;
2828

29+
namespace mlir {
30+
#define GEN_PASS_DEF_CIRCANONICALIZE
31+
#include "clang/CIR/Dialect/Passes.h.inc"
32+
} // namespace mlir
33+
2934
namespace {
3035

3136
/// Removes branches between two blocks if it is the only branch.
@@ -101,7 +106,8 @@ struct RemoveEmptySwitch : public OpRewritePattern<SwitchOp> {
101106
// CIRCanonicalizePass
102107
//===----------------------------------------------------------------------===//
103108

104-
struct CIRCanonicalizePass : public CIRCanonicalizeBase<CIRCanonicalizePass> {
109+
struct CIRCanonicalizePass
110+
: public impl::CIRCanonicalizeBase<CIRCanonicalizePass> {
105111
using CIRCanonicalizeBase::CIRCanonicalizeBase;
106112

107113
// The same operation rewriting done here could have been performed

clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
using namespace mlir;
2222
using namespace cir;
2323

24+
namespace mlir {
25+
#define GEN_PASS_DEF_CIRSIMPLIFY
26+
#include "clang/CIR/Dialect/Passes.h.inc"
27+
} // namespace mlir
28+
2429
//===----------------------------------------------------------------------===//
2530
// Rewrite patterns
2631
//===----------------------------------------------------------------------===//
@@ -283,7 +288,7 @@ struct SimplifyVecSplat : public OpRewritePattern<VecSplatOp> {
283288
// CIRSimplifyPass
284289
//===----------------------------------------------------------------------===//
285290

286-
struct CIRSimplifyPass : public CIRSimplifyBase<CIRSimplifyPass> {
291+
struct CIRSimplifyPass : public impl::CIRSimplifyBase<CIRSimplifyPass> {
287292
using CIRSimplifyBase::CIRSimplifyBase;
288293

289294
void runOnOperation() override;

clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
using namespace mlir;
2727
using namespace cir;
2828

29+
namespace mlir {
30+
#define GEN_PASS_DEF_CIRFLATTENCFG
31+
#include "clang/CIR/Dialect/Passes.h.inc"
32+
} // namespace mlir
33+
2934
namespace {
3035

3136
/// Lowers operations with the terminator trait that have a single successor.
@@ -50,7 +55,7 @@ void walkRegionSkipping(
5055
});
5156
}
5257

53-
struct CIRFlattenCFGPass : public CIRFlattenCFGBase<CIRFlattenCFGPass> {
58+
struct CIRFlattenCFGPass : public impl::CIRFlattenCFGBase<CIRFlattenCFGPass> {
5459

5560
CIRFlattenCFGPass() = default;
5661
void runOnOperation() override;

clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
using namespace mlir;
1515
using namespace cir;
1616

17+
namespace mlir {
18+
#define GEN_PASS_DEF_GOTOSOLVER
19+
#include "clang/CIR/Dialect/Passes.h.inc"
20+
} // namespace mlir
21+
1722
namespace {
1823

19-
struct GotoSolverPass : public GotoSolverBase<GotoSolverPass> {
24+
struct GotoSolverPass : public impl::GotoSolverBase<GotoSolverPass> {
2025
GotoSolverPass() = default;
2126
void runOnOperation() override;
2227
};

clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
using namespace mlir;
2121
using namespace cir;
2222

23+
namespace mlir {
24+
#define GEN_PASS_DEF_HOISTALLOCAS
25+
#include "clang/CIR/Dialect/Passes.h.inc"
26+
} // namespace mlir
27+
2328
namespace {
2429

25-
struct HoistAllocasPass : public HoistAllocasBase<HoistAllocasPass> {
30+
struct HoistAllocasPass : public impl::HoistAllocasBase<HoistAllocasPass> {
2631

2732
HoistAllocasPass() = default;
2833
void runOnOperation() override;

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
using namespace mlir;
2424
using namespace cir;
2525

26+
namespace mlir {
27+
#define GEN_PASS_DEF_LOWERINGPREPARE
28+
#include "clang/CIR/Dialect/Passes.h.inc"
29+
} // namespace mlir
30+
2631
static SmallString<128> getTransformedFileName(mlir::ModuleOp mlirModule) {
2732
SmallString<128> fileName;
2833

@@ -53,7 +58,8 @@ static cir::FuncOp getCalledFunction(cir::CallOp callOp) {
5358
}
5459

5560
namespace {
56-
struct LoweringPreparePass : public LoweringPrepareBase<LoweringPreparePass> {
61+
struct LoweringPreparePass
62+
: public impl::LoweringPrepareBase<LoweringPreparePass> {
5763
LoweringPreparePass() = default;
5864
void runOnOperation() override;
5965

clang/lib/CIR/Dialect/Transforms/PassDetail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace mlir {
2121
template <typename ConcreteDialect>
2222
void registerDialect(DialectRegistry &registry);
2323

24-
#define GEN_PASS_CLASSES
24+
#define GEN_PASS_DECL
2525
#include "clang/CIR/Dialect/Passes.h.inc"
2626

2727
} // namespace mlir

0 commit comments

Comments
 (0)