Skip to content

Inlining function with mismatching target feature using [[gnu::flatten]] attribute causes fatal error #149866

@mjacobse

Description

@mjacobse

This minimal example leads to a fatal error (https://godbolt.org/z/Y6cM836Ts):

#include <smmintrin.h>

[[gnu::target("sse4.1")]]
__m128d test_impl() {
    return _mm_ceil_pd(_mm_set_sd(0.0));
}

[[gnu::flatten]]
__m128d test() {
    return test_impl();
}
fatal error: error in backend: Cannot select: 0x497142f0: v2f64 = X86ISD::VRNDSCALE 0x49714520, TargetConstant:i32<2>, example.c:5:12 @[ example.c:10:12 ]
  0x49714520: v2f64 = BUILD_VECTOR ConstantFP:f64<0.000000e+00>, ConstantFP:f64<0.000000e+00>, example.c:5:12 @[ example.c:10:12 ]
    0x49714440: f64 = ConstantFP<0.000000e+00>
    0x49714440: f64 = ConstantFP<0.000000e+00>
  0x49714210: i32 = TargetConstant<2>
In function: test

Using [[gnu::always_inline]] on test_impl instead of using [[gnu::flatten]] on test gives a helpful error message instead (https://godbolt.org/z/d5ebWj47n):

<source>:9:5: error: always_inline function 'test_impl' requires target feature 'sse4.1', but would be inlined into function 'test' that is compiled without support for 'sse4.1'
    9 |     test_impl();
      |     ^
1 error generated.
Compiler returned: 1

I am not entirely sure if the same helpful error message should be generated for the initial example, or if the target mismatch should overrule the flatten attribute instead, such that the function is simply not inlined. FWIW, gcc seems to do the 2nd option (https://godbolt.org/z/6Taf8qhzT). But either option seems preferable to the not so helpful fatal error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:X86clang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]llvm:SelectionDAGSelectionDAGISel as well

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions