Skip to content

Commit da4f86e

Browse files
committed
Lower vld1_dup and vld1q_dup
1 parent 9975749 commit da4f86e

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,13 +2821,16 @@ def VecSplatOp : CIR_Op<"vec.splat", [Pure,
28212821
let description = [{
28222822
The `cir.vec.splat` operation creates a vector value from a scalar value.
28232823
All elements of the vector have the same value, that of the given scalar.
2824+
If `poison` is specified, the start value of the result is poison values
2825+
instead of undef.
28242826
}];
28252827

2826-
let arguments = (ins CIR_AnyType:$value);
2828+
let arguments = (ins CIR_AnyType:$value, UnitAttr:$poison);
28272829
let results = (outs CIR_VectorType:$result);
28282830

28292831
let assemblyFormat = [{
2830-
$value `:` type($value) `,` qualified(type($result)) attr-dict
2832+
$value `:` type($value) `,` qualified(type($result))
2833+
(`poison` $poison^)? attr-dict
28312834
}];
28322835
let hasVerifier = 0;
28332836
}

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,9 @@ static mlir::cir::VectorType GetNeonType(CIRGenFunction *CGF,
19491949
CGF->getCIRGenModule().FloatTy,
19501950
V1Ty ? 1 : (2 << IsQuad));
19511951
case NeonTypeFlags::Float64:
1952-
llvm_unreachable("NYI");
1952+
return mlir::cir::VectorType::get(CGF->getBuilder().getContext(),
1953+
CGF->getCIRGenModule().DoubleTy,
1954+
V1Ty ? 1 : (1 << IsQuad));
19531955
}
19541956
llvm_unreachable("Unknown vector element type!");
19551957
}
@@ -3411,7 +3413,12 @@ CIRGenFunction::buildAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
34113413
}
34123414
case NEON::BI__builtin_neon_vld1_dup_v:
34133415
case NEON::BI__builtin_neon_vld1q_dup_v: {
3414-
llvm_unreachable("NYI");
3416+
cir::Address ptrAddr = PtrOp0.withElementType(VTy.getEltType());
3417+
mlir::Value val = builder.createLoad(getLoc(E->getExprLoc()), ptrAddr);
3418+
mlir::cir::VecSplatOp vecSplat = builder.create<mlir::cir::VecSplatOp>(
3419+
getLoc(E->getExprLoc()), VTy, val);
3420+
vecSplat.setPoison(true);
3421+
return vecSplat;
34153422
}
34163423
case NEON::BI__builtin_neon_vst1_lane_v:
34173424
case NEON::BI__builtin_neon_vst1q_lane_v:

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,15 +1435,18 @@ class CIRVectorSplatLowering
14351435
assert(vecTy && "result type of cir.vec.splat op is not VectorType");
14361436
auto llvmTy = typeConverter->convertType(vecTy);
14371437
auto loc = op.getLoc();
1438-
mlir::Value undef = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
1438+
mlir::Value startVal =
1439+
op.getPoison()
1440+
? rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy).getRes()
1441+
: rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
14391442
mlir::Value indexValue =
14401443
rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), 0);
14411444
mlir::Value elementValue = adaptor.getValue();
14421445
mlir::Value oneElement = rewriter.create<mlir::LLVM::InsertElementOp>(
1443-
loc, undef, elementValue, indexValue);
1446+
loc, startVal, elementValue, indexValue);
14441447
SmallVector<int32_t> zeroValues(vecTy.getSize(), 0);
14451448
mlir::Value shuffled = rewriter.create<mlir::LLVM::ShuffleVectorOp>(
1446-
loc, oneElement, undef, zeroValues);
1449+
loc, oneElement, startVal, zeroValues);
14471450
rewriter.replaceOp(op, shuffled);
14481451
return mlir::success();
14491452
}

0 commit comments

Comments
 (0)