================ @@ -157,6 +158,35 @@ static bool expandAnyIntrinsic(CallInst *Orig) { return true; } +static bool expandLengthIntrinsic(CallInst *Orig) { + Value *X = Orig->getOperand(0); + IRBuilder<> Builder(Orig->getParent()); + Builder.SetInsertPoint(Orig); + Type *Ty = X->getType(); + Type *EltTy = Ty->getScalarType(); + + // Though dx.length does work on scalar type, we can optimize it to just emit + // fabs, in CGBuiltin.cpp. We shouldn't see a scalar type here because + // CGBuiltin.cpp should have emitted a fabs call. + Value *Elt = Builder.CreateExtractElement(X, (uint64_t)0); + auto *XVec = dyn_cast<FixedVectorType>(Ty); + unsigned size = XVec->getNumElements(); + assert(Ty->isVectorTy() && size > 1 && "dx.length only works on vector type"); + + Value *Sum = Builder.CreateFMul(Elt, Elt); + for (unsigned i = 1; i < size; i++) { + Elt = Builder.CreateExtractElement(X, i); ---------------- bogner wrote:
Style nit, "i" should be capitalized ```suggestion for (unsigned I = 1; I < size; I++) { Elt = Builder.CreateExtractElement(X, I); ``` https://github.com/llvm/llvm-project/pull/101256 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits