[clang] [llvm] Add cross builtins and cross HLSL function to DirectX and SPIR-V backend (PR #109180)
Joshua Batista via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 13:27:33 PDT 2024
================
@@ -74,6 +75,42 @@ static Value *expandAbs(CallInst *Orig) {
"dx.max");
}
+static Value *expandCrossIntrinsic(CallInst *Orig) {
+
+ VectorType *VT = cast<VectorType>(Orig->getType());
+ if (cast<FixedVectorType>(VT)->getNumElements() != 3)
+ report_fatal_error(Twine("return vector must have exactly 3 elements"),
+ /* gen_crash_diag=*/false);
+
+ Value *op0 = Orig->getOperand(0);
+ Value *op1 = Orig->getOperand(1);
+ IRBuilder<> Builder(Orig);
+
+ Value *op0_x = Builder.CreateExtractElement(op0, (uint64_t)0, "x0");
+ Value *op0_y = Builder.CreateExtractElement(op0, 1, "x1");
+ Value *op0_z = Builder.CreateExtractElement(op0, 2, "x2");
+
+ Value *op1_x = Builder.CreateExtractElement(op1, (uint64_t)0, "y0");
+ Value *op1_y = Builder.CreateExtractElement(op1, 1, "y1");
+ Value *op1_z = Builder.CreateExtractElement(op1, 2, "y2");
+
+ auto MulSub = [&](Value *x0, Value *y0, Value *x1, Value *y1) -> Value * {
+ Value *xy = Builder.CreateFMul(x0, y1);
+ Value *yx = Builder.CreateFMul(y0, x1);
+ return Builder.CreateFSub(xy, yx);
----------------
bob80905 wrote:
I tried it out and turns out each variable was assigned a unique variable name, contrary to what I expected. So your comment has been incorporated.
https://github.com/llvm/llvm-project/pull/109180
More information about the cfe-commits
mailing list