@@ -3326,8 +3326,12 @@ func.func @from_elements_to_elements_shuffle(%a: vector<4x2xf32>) -> vector<4x2x
33263326
33273327// -----
33283328
3329- // CHECK-LABEL: func @from_elements_all_elements_constant(
3330- func.func @from_elements_all_elements_constant () -> vector <2 x2 xi32 > {
3329+ // +---------------------------------------------------------------------------
3330+ // Tests for foldFromElementsToConstant
3331+ // +---------------------------------------------------------------------------
3332+
3333+ // CHECK-LABEL: func @from_elements_to_constant(
3334+ func.func @from_elements_to_constant () -> vector <2 x2 xi32 > {
33313335 %c0_i32 = arith.constant 0 : i32
33323336 %c1_i32 = arith.constant 1 : i32
33333337 %c2_i32 = arith.constant 2 : i32
@@ -3340,9 +3344,11 @@ func.func @from_elements_all_elements_constant() -> vector<2x2xi32> {
33403344
33413345// -----
33423346
3343- // CHECK-LABEL: func @from_elements_partial_elements_constant(
3347+ // One of the elements is not a constant, the folder should fail.
3348+
3349+ // CHECK-LABEL: func @negative_from_elements_to_constant(
33443350// CHECK-SAME: %[[A:.*]]: f32
3345- func.func @from_elements_partial_elements_constant (%arg0: f32 ) -> vector <2 xf32 > {
3351+ func.func @negative_from_elements_to_constant (%arg0: f32 ) -> vector <2 xf32 > {
33463352 // CHECK: %[[C:.*]] = arith.constant 1.000000e+00 : f32
33473353 %c = arith.constant 1.0 : f32
33483354 // CHECK: %[[RES:.*]] = vector.from_elements %[[A]], %[[C]] : vector<2xf32>
@@ -3353,6 +3359,28 @@ func.func @from_elements_partial_elements_constant(%arg0: f32) -> vector<2xf32>
33533359
33543360// -----
33553361
3362+ // While all inputs in this example are constant, we cannot create a
3363+ // DenselElemAttr containing llvm.mlir.addressof. Instead,
3364+ // `foldFromElementsToConstant` bails out. Note that in this case, a different
3365+ // folder is applied (`rewriteFromElementsAsBroadcast`).
3366+ llvm.mlir.global constant @my_symbol () : i32
3367+
3368+ // CHECK-LABEL: func @negative_from_elements_to_constant
3369+ // CHECK: %[[A:.*]] = llvm.mlir.addressof @my_symbol
3370+ // CHECK: %[[B:.*]] = vector.broadcast %[[A]] : !llvm.ptr to vector<1x!llvm.ptr>
3371+ // CHECK: return %[[B]]
3372+ func.func @negative_from_elements_to_constant () -> vector <1 x!llvm.ptr > {
3373+ %a = llvm.mlir.addressof @my_symbol : !llvm.ptr
3374+ %b = vector.from_elements %a : vector <1 x!llvm.ptr >
3375+ return %b : vector <1 x!llvm.ptr >
3376+ }
3377+
3378+ // +---------------------------------------------------------------------------
3379+ // End of Tests for foldFromElementsToConstant
3380+ // +---------------------------------------------------------------------------
3381+
3382+ // -----
3383+
33563384// CHECK-LABEL: func @vector_insert_const_regression(
33573385// CHECK: llvm.mlir.undef
33583386// CHECK: vector.insert
@@ -3726,17 +3754,3 @@ func.func @no_fold_insert_use_chain_mismatch_static_position(%arg : vector<4xf32
37263754 %v_1 = vector.insert %val , %v_0 [1 ] : f32 into vector <4 xf32 >
37273755 return %v_1 : vector <4 xf32 >
37283756}
3729-
3730- // -----
3731-
3732- llvm.mlir.global constant @my_symbol () : i32
3733-
3734- // CHECK-LABEL: func @from_address_of_regression
3735- // CHECK: %[[a:.*]] = llvm.mlir.addressof @my_symbol
3736- // CHECK: %[[b:.*]] = vector.broadcast %[[a]] : !llvm.ptr to vector<1x!llvm.ptr>
3737- // CHECK: return %[[b]]
3738- func.func @from_address_of_regression () -> vector <1 x!llvm.ptr > {
3739- %a = llvm.mlir.addressof @my_symbol : !llvm.ptr
3740- %b = vector.from_elements %a : vector <1 x!llvm.ptr >
3741- return %b : vector <1 x!llvm.ptr >
3742- }
0 commit comments