Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen] Support OpenCL Vector Types #613

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

seven-mile
Copy link
Collaborator

@seven-mile seven-mile commented May 16, 2024

Fix #532 .

Support CIRGen of ExtVectorElementExpr that includes swizzle v.xyx and subscription v.s0.

@seven-mile seven-mile marked this pull request as ready for review May 16, 2024 18:38
@@ -646,9 +646,69 @@ RValue CIRGenFunction::buildLoadOfLValue(LValue LV, SourceLocation Loc) {

if (LV.isSimple())
return RValue::get(buildLoadOfScalar(LV, Loc));

if (LV.isVectorElt()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is content from the other patch? If there are dependencies between the PRs, it might be better not to put them up for review just yet, otherwise I have to go to the same thing twice and mentally account for it :)

clang/test/CIR/Lowering/vectype-cl.cpp Outdated Show resolved Hide resolved
clang/test/CIR/Lowering/vectype-cl.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/vectype-cl.cpp Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/vectype-cl.cpp Outdated Show resolved Hide resolved
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to go on the skeleton work and thanks for fixing the testcase, more comments inline.

llvm_unreachable("NYI");
}

int64_t CIRGenFunction::getAccessedFieldNo(unsigned int idx,
const mlir::Attribute elts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the uses I've seen elsewhere, elts param could just be a ArrayAttr

assert(elts.isa<mlir::ArrayAttr>());

auto elt = elts.cast<mlir::ArrayAttr>()[idx];
assert(elt.isa<mlir::IntegerAttr>());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are doing a isa followed by cast, better just do dyn_cast and assert if it's null.

// HLSL allows treating scalars as one-element vectors. Converting the scalar
// IR value to a vector here allows the rest of codegen to behave as normal.
if (getLangOpts().HLSL && !Vec.getType().isa<mlir::cir::VectorType>()) {
auto DstTy =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paths that are not tested should be llvm_unreachable("NYI");. Unless you are adding HLSL tests, please remove the code within this if statement in favor of llvm_unreachable("NYI");. Please do that for all other places where you didn't add tests to cover those paths.

// a single element. Just codegen as an extractelement.
const auto *ExprVT = LV.getType()->getAs<clang::VectorType>();
if (!ExprVT) {
int64_t InIdx = getAccessedFieldNo(0, Elts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this path tested?

@@ -674,6 +727,84 @@ RValue CIRGenFunction::buildLoadOfBitfieldLValue(LValue LV,
return RValue::get(field);
}

void CIRGenFunction::buildStoreThroughExtVectorComponentLValue(RValue Src,
LValue Dst) {
mlir::Location loc = Dst.getExtVectorPointer().getLoc();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this function, please make sure you add testcases or llvm_unreachable("NYI"); for paths that are not tested.

LValue
CIRGenFunction::buildExtVectorElementExpr(const ExtVectorElementExpr *E) {
// Emit the base vector as an l-value.
LValue Base;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this function, please make sure you add testcases or llvm_unreachable("NYI"); for paths that are not tested.

// If it is a pointer to a vector, emit the address and form an lvalue with
// it.
LValueBaseInfo BaseInfo;
// TODO(cir): Support TBAA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add assert(!UnimplementedFeature::tbaa());

// OpenCL: If the condition is a vector, we can treat this condition like
// the select function.
if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) ||
condExpr->getType()->isExtVectorType()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing this check? I don't think you have testcases to back this up and doing this will probably lead to some mis-compilation that is going hard to track later. There's specific handling that needs to be done for VisitAbstractConditionalOperator in face of these conditions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector_ternary_lowering is on this path. This was mentioned in the PR description (I'll update it to a brief version though):

A special method is used for the original CodeGen for ternary operator of OpenCL vectors. I don't know why. Since we already have high-level cir.vec.ternary, I skipped this part. And the lowering still works well. Maybe it's about the SPIR-V target.

Probably I'll also comment the corresponding part in the PR review ahead of time : )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have high-level cir.vec.ternary, I skipped this part

Unfortunately that's not a good rationale and not how we usually go about these things in CIR - if this leads to a miscompile, it's going to be really hard to pinpoint the issue, and might take a lot of investigation time. If something was implemented that is shortcuting here, it should also be fixed to maintain the skeleton the much pristine as possible. It's possible you might find out that you need to do another PR to fix that problem before you can land this one.

Alternatively, if you are deleting this code so one of your testcases may pass, you can then choose to not add that testcase and address the whole issue together in another PR.

assert(isExtVectorElt());
return V;
}
mlir::Attribute getExtVectorElts() const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From overall usage in this PR, looks like this could return an ArrayAttr instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenCL vector types
2 participants