Skip to content

Commit 2b94285

Browse files
authored
[CIR][CIRGen] handle vectors of size 3 like size 4 for better performance (#1363)
This PR removes XFAIL test_vec3
1 parent dbe544d commit 2b94285

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "mlir/IR/Operation.h"
4040
#include "mlir/IR/Value.h"
4141

42+
#include <numeric>
43+
4244
using namespace clang;
4345
using namespace clang::CIRGen;
4446
using namespace cir;
@@ -2936,7 +2938,13 @@ mlir::Value CIRGenFunction::emitLoadOfScalar(Address addr, bool isVolatile,
29362938
CGM.getABIInfo().getOptimalVectorMemoryType(vTy, getLangOpts());
29372939

29382940
if (vTy != newVecTy) {
2939-
llvm_unreachable("NYI");
2941+
const Address cast = addr.withElementType(newVecTy);
2942+
mlir::Value v = builder.createLoad(loc, cast, isVolatile);
2943+
const uint64_t oldNumElements = vTy.getSize();
2944+
SmallVector<int64_t, 16> mask(oldNumElements);
2945+
std::iota(mask.begin(), mask.end(), 0);
2946+
v = builder.createVecShuffle(loc, v, mask);
2947+
return emitFromMemory(v, ty);
29402948
}
29412949
}
29422950

clang/lib/CIR/CodeGen/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ cir::VectorType
378378
ABIInfo::getOptimalVectorMemoryType(cir::VectorType T,
379379
const clang::LangOptions &Opt) const {
380380
if (T.getSize() == 3 && !Opt.PreserveVec3Type) {
381-
llvm_unreachable("NYI");
381+
return cir::VectorType::get(&CGT.getMLIRContext(), T.getEltType(), 4);
382382
}
383383
return T;
384384
}

clang/test/CIR/CodeGen/vectype-ext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
33
// RUN: %clang_cc1 -std=c++17 -fclangir -emit-llvm -triple x86_64-unknown-linux-gnu %s -o %t.ll
44
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
5-
// XFAIL: *
65

76
typedef int vi4 __attribute__((ext_vector_type(4)));
87
typedef int vi3 __attribute__((ext_vector_type(3)));

0 commit comments

Comments
 (0)