[clang] [CIR] Lowering for __builtin_reduce_assoc_fadd (PR #226095)
Kunal Dubey via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 29 19:58:51 PDT 2026
================
@@ -110,9 +110,42 @@ float test_reduce_min_float(v4sf x) {
return __builtin_reduce_min(x);
}
+float test_reduce_assoc_fadd(v4sf x, float start) {
+ // CIR-LABEL: @test_reduce_assoc_fadd
+ // CIR: cir.call_llvm_intrinsic "vector.reduce.fadd" {{.*}} : (!cir.float, !cir.vector<4 x !cir.float>) -> !cir.float {fastmath_flags = #cir.fastmath<reassoc>}
+ // CIR: cir.return
+ // LLVM-LABEL: @test_reduce_assoc_fadd
+ // LLVM: call reassoc float @llvm.vector.reduce.fadd.v4f32(float %{{.*}}, <4 x float>
+ // LLVM: ret float
+ return __builtin_reduce_assoc_fadd(x, start);
+}
+
+float test_reduce_assoc_fadd_default_start(v4sf x) {
+ // CIR-LABEL: @test_reduce_assoc_fadd_default_start
+ // CIR: %[[START:.*]] = cir.const #cir.fp<-0.000000e+00> : !cir.float
+ // CIR: cir.call_llvm_intrinsic "vector.reduce.fadd" %[[START]], {{.*}} : (!cir.float, !cir.vector<4 x !cir.float>) -> !cir.float {fastmath_flags = #cir.fastmath<reassoc>}
+ // CIR: cir.return
+ // LLVM-LABEL: @test_reduce_assoc_fadd_default_start
+ // LLVM: call reassoc float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float>
+ // LLVM: ret float
+ return __builtin_reduce_assoc_fadd(x);
+}
+
+float test_reduce_assoc_fadd_cast_start(v4sf x, double start) {
+ // CIR-LABEL: @test_reduce_assoc_fadd_cast_start
+ // CIR: %[[START:.*]] = cir.cast floating {{.*}} : !cir.double -> !cir.float
+ // CIR: cir.call_llvm_intrinsic "vector.reduce.fadd" %[[START]], {{.*}} : (!cir.float, !cir.vector<4 x !cir.float>) -> !cir.float {fastmath_flags = #cir.fastmath<reassoc>}
+ // CIR: cir.return
+ // LLVM-LABEL: @test_reduce_assoc_fadd_cast_start
+ // LLVM: %[[START:.*]] = fptrunc double %{{.*}} to float
+ // LLVM: call reassoc float @llvm.vector.reduce.fadd.v4f32(float %[[START]], <4 x float>
+ // LLVM: ret float
+ return __builtin_reduce_assoc_fadd(x, start);
+}
+
float test_reduce_in_order_fadd(v4sf x, float start) {
// CIR-LABEL: @test_reduce_in_order_fadd
- // CIR: cir.call_llvm_intrinsic "vector.reduce.fadd" {{.*}} : (!cir.float, !cir.vector<4 x !cir.float>) -> !cir.float
+ // CIR: cir.call_llvm_intrinsic "vector.reduce.fadd" {{.*}} : (!cir.float, !cir.vector<4 x !cir.float>) -> !cir.float{{( loc.*)?$}}
----------------
xakep8 wrote:
It is to handle something like this `!cir.float {fastmath_flags = #cir.fastmath<reassoc>} loc(...)` which has fast-math flags. It is ensuring the intrinsic has no trailing attributes. While this will also ignore optional location suffix.
https://github.com/llvm/llvm-project/pull/226095
More information about the cfe-commits
mailing list