Skip to content

Commit 24b361c

Browse files
ghehglanza
authored andcommitted
[CIR][Lowering] VecCreateOp and VecSplatOp lowering choose LLVM:PoisonOp (#959)
They should use PoisonOp (which becomes PoisonValue in LLVMIR) as it is the OG's choice. Proof: We generate VecCreateOp [here ](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp#L1975) And it's OG counterpart is [here](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/clang/lib/CodeGen/CGExprScalar.cpp#L2096) OG uses PoisonValue. As to VecSplatOp, OG unconditionally [chooses PoisonValue ](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/llvm/lib/IR/IRBuilder.cpp#L1204) A even more solid proof for this case is that when we use OG to generate code for our test case I changed in this PR , its always using poison instead of undef as far as VecSplat and VecCreate is concerned. The [OG generated code for vectype-ext.cpp ](https://godbolt.org/z/eqx1rns86) here. The [OG generated code for vectype.cpp ](https://godbolt.org/z/frMjbKGeT) here. For reference, generated CIR for the test case vectype-ext.cpp is [here](https://godbolt.org/z/frMjbKGeT) This is to unblock #936 to help it set on the right path. Note: There might be other CIR vec ops that need to choose Poison to be consistent with OG, but I'd limit the scope of this PR, and wait to see issue pop up in the future.
1 parent 65b9e9b commit 24b361c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ class CIRVectorCreateLowering
16111611
assert(vecTy && "result type of cir.vec.create op is not VectorType");
16121612
auto llvmTy = typeConverter->convertType(vecTy);
16131613
auto loc = op.getLoc();
1614-
mlir::Value result = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
1614+
mlir::Value result = rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy);
16151615
assert(vecTy.getSize() == op.getElements().size() &&
16161616
"cir.vec.create op count doesn't match vector type elements count");
16171617
for (uint64_t i = 0; i < vecTy.getSize(); ++i) {
@@ -1676,7 +1676,7 @@ class CIRVectorSplatLowering
16761676
assert(vecTy && "result type of cir.vec.splat op is not VectorType");
16771677
auto llvmTy = typeConverter->convertType(vecTy);
16781678
auto loc = op.getLoc();
1679-
mlir::Value undef = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
1679+
mlir::Value undef = rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy);
16801680
mlir::Value indexValue =
16811681
rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), 0);
16821682
mlir::Value elementValue = adaptor.getValue();

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void vector_int_test(int x) {
2626
// LLVM: %[[#X1:]] = load i32, ptr %{{[0-9]+}}, align 4
2727
// LLVM-NEXT: %[[#X2:]] = load i32, ptr %{{[0-9]+}}, align 4
2828
// LLVM-NEXT: %[[#SUM:]] = add nsw i32 %[[#X2]], 1
29-
// LLVM-NEXT: %[[#VEC1:]] = insertelement <4 x i32> undef, i32 %[[#X1]], i64 0
29+
// LLVM-NEXT: %[[#VEC1:]] = insertelement <4 x i32> poison, i32 %[[#X1]], i64 0
3030
// LLVM-NEXT: %[[#VEC2:]] = insertelement <4 x i32> %[[#VEC1]], i32 5, i64 1
3131
// LLVM-NEXT: %[[#VEC3:]] = insertelement <4 x i32> %[[#VEC2]], i32 6, i64 2
3232
// LLVM-NEXT: %[[#VEC4:]] = insertelement <4 x i32> %[[#VEC3]], i32 %[[#SUM]], i64 3
@@ -39,7 +39,7 @@ void vector_int_test(int x) {
3939
// LLVM: %[[#X1:]] = load i32, ptr %{{[0-9]+}}, align 4
4040
// LLVM-NEXT: %[[#X2:]] = load i32, ptr %{{[0-9]+}}, align 4
4141
// LLVM-NEXT: %[[#SUM:]] = add nsw i32 %[[#X2]], 1
42-
// LLVM-NEXT: %[[#VEC1:]] = insertelement <4 x i32> undef, i32 %[[#X1]], i64 0
42+
// LLVM-NEXT: %[[#VEC1:]] = insertelement <4 x i32> poison, i32 %[[#X1]], i64 0
4343
// LLVM-NEXT: %[[#VEC2:]] = insertelement <4 x i32> %[[#VEC1]], i32 %[[#SUM]], i64 1
4444
// LLVM-NEXT: %[[#VEC3:]] = insertelement <4 x i32> %[[#VEC2]], i32 0, i64 2
4545
// LLVM-NEXT: %[[#VEC4:]] = insertelement <4 x i32> %[[#VEC3]], i32 0, i64 3
@@ -212,7 +212,7 @@ void vector_double_test(int x, double y) {
212212
// LLVM: %[[#Y1:]] = load double, ptr %{{[0-9]+}}, align 8
213213
// LLVM-NEXT: %[[#Y2:]] = load double, ptr %{{[0-9]+}}, align 8
214214
// LLVM-NEXT: %[[#SUM:]] = fadd double %[[#Y2]], 1.000000e+00
215-
// LLVM-NEXT: %[[#VEC1:]] = insertelement <2 x double> undef, double %[[#Y1]], i64 0
215+
// LLVM-NEXT: %[[#VEC1:]] = insertelement <2 x double> poison, double %[[#Y1]], i64 0
216216
// LLVM-NEXT: %[[#VEC2:]] = insertelement <2 x double> %[[#VEC1]], double %[[#SUM]], i64 1
217217
// LLVM-NEXT: store <2 x double> %[[#VEC2]], ptr %{{[0-9]+}}, align 16
218218

@@ -222,7 +222,7 @@ void vector_double_test(int x, double y) {
222222
// CIR: %{{[0-9]+}} = cir.vec.create(%{{[0-9]+}}, %[[#dzero]] : !cir.double, !cir.double) : !cir.vector<!cir.double x 2>
223223

224224
// LLVM: %[[#Y1:]] = load double, ptr %{{[0-9]+}}, align 8
225-
// LLVM-NEXT: %[[#VEC1:]] = insertelement <2 x double> undef, double %[[#Y1]], i64 0
225+
// LLVM-NEXT: %[[#VEC1:]] = insertelement <2 x double> poison, double %[[#Y1]], i64 0
226226
// LLVM-NEXT: %[[#VEC2:]] = insertelement <2 x double> %[[#VEC1]], double 0.000000e+00, i64 1
227227
// LLVM-NEXT: store <2 x double> %[[#VEC2]], ptr %{{[0-9]+}}, align 16
228228

clang/test/CIR/Lowering/vectype.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
22
// RUN: cir-opt %t.cir -cir-to-llvm -o %t.mlir
3+
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ii
34
// RUN: FileCheck --input-file=%t.mlir %s
45
// XFAIL: *
56

@@ -23,7 +24,7 @@ void vector_int_test(int x) {
2324
// CHECK: %[[#T46:]] = llvm.load %[[#T1]] {alignment = 4 : i64} : !llvm.ptr -> i32
2425
// CHECK: %[[#T47:]] = llvm.mlir.constant(1 : i32) : i32
2526
// CHECK: %[[#T48:]] = llvm.add %[[#T46]], %[[#T47]] overflow<nsw> : i32
26-
// CHECK: %[[#T49:]] = llvm.mlir.undef : vector<4xi32>
27+
// CHECK: %[[#T49:]] = llvm.mlir.poison : vector<4xi32>
2728
// CHECK: %[[#T50:]] = llvm.mlir.constant(0 : i64) : i64
2829
// CHECK: %[[#T51:]] = llvm.insertelement %[[#T43]], %[[#T49]][%[[#T50]] : i64] : vector<4xi32>
2930
// CHECK: %[[#T52:]] = llvm.mlir.constant(1 : i64) : i64
@@ -42,10 +43,10 @@ void vector_int_test(int x) {
4243

4344
// Scalar to vector conversion, a.k.a. vector splat.
4445
b = a + 7;
45-
// CHECK: %[[#undef:]] = llvm.mlir.undef : vector<4xi32>
46+
// CHECK: %[[#poison:]] = llvm.mlir.poison : vector<4xi32>
4647
// CHECK: %[[#zeroInt:]] = llvm.mlir.constant(0 : i64) : i64
47-
// CHECK: %[[#inserted:]] = llvm.insertelement %[[#seven:]], %[[#undef]][%[[#zeroInt]] : i64] : vector<4xi32>
48-
// CHECK: %[[#shuffled:]] = llvm.shufflevector %[[#inserted]], %[[#undef]] [0, 0, 0, 0] : vector<4xi32>
48+
// CHECK: %[[#inserted:]] = llvm.insertelement %[[#seven:]], %[[#poison]][%[[#zeroInt]] : i64] : vector<4xi32>
49+
// CHECK: %[[#shuffled:]] = llvm.shufflevector %[[#inserted]], %[[#poison]] [0, 0, 0, 0] : vector<4xi32>
4950

5051
// Extract element.
5152
int c = a[x];
@@ -234,7 +235,7 @@ void vector_double_test(int x, double y) {
234235
// CHECK: %[[#T30:]] = llvm.load %[[#T3]] {alignment = 8 : i64} : !llvm.ptr -> f64
235236
// CHECK: %[[#T31:]] = llvm.mlir.constant(1.000000e+00 : f64) : f64
236237
// CHECK: %[[#T32:]] = llvm.fadd %[[#T30]], %[[#T31]] : f64
237-
// CHECK: %[[#T33:]] = llvm.mlir.undef : vector<2xf64>
238+
// CHECK: %[[#T33:]] = llvm.mlir.poison : vector<2xf64>
238239
// CHECK: %[[#T34:]] = llvm.mlir.constant(0 : i64) : i64
239240
// CHECK: %[[#T35:]] = llvm.insertelement %[[#T29]], %[[#T33]][%[[#T34]] : i64] : vector<2xf64>
240241
// CHECK: %[[#T36:]] = llvm.mlir.constant(1 : i64) : i64

0 commit comments

Comments
 (0)