Issue 83134
Summary [LLVM][CodeGen][InlineAssembly] Invalid inline assembly for subtarget compiles without error.
Labels backend:X86, accepts-invalid, inline-asm
Assignees
Reporter spaits
    ## Environmet inforamtion
clang version: Ubuntu clang version 14.0.0-1ubuntu1.1
cpu: 12th Gen Intel i7-1265U (12) @ 4.800GHz

## The problem
LLVM backend accepts inline assembly instructions that is not supported by the sub-target. This happens even if the `-mno-<<feature name>>` flag is used to explicitly disable the feature. I think there should be a compile error here telling the user that the inline assembly is invalid.

## The reproduction of the issue
Let's have the following code that should work on x86-64 CPUs that support the AVX-512 feature:
```cpp
#include <iostream>

int main() {
    double a[8] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
    double b[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
    double c[8] = {0};

    asm volatile(
        "vmovupd %0, %%zmm0\n\t"
        "vmovupd %1, %%zmm1\n\t"
        "vaddpd %%zmm0, %%zmm1, %%zmm2\n\t"
 "vmovupd %%zmm2, %2"
        : 
        : "m" (a), "m" (b), "m" (c)
        : "zmm0", "zmm1", "zmm2"
    );

    for (int i = 0; i < 8; i++) {
        std::cout << c[i] << " ";
    }
 std::cout << std::endl;

    return 0;
}
```
I compile the code with the following command:
```
clang++ --target=x86_64-pc-linux-gnu -mno-avx512f
```
I put the `-mno-avx512f` flag there to NOT use  AVX-512 specific features.

The compilation finishes with no error. I get the executable.
When I try to run the executable I get the following error:
```
Illegal instruction (core dumped)
```
I have a `12th Gen Intel i7-1265U` CPU in my machine. This CPU does not support AVX-512 feature.

## Potential cause of this issue

The `MatchInstructionImpl` function that is generated in the `X86GenAsmMatcher.cpp` file returns with the value Match_Success (4) value even if the feature required for the instruction is off. I did some additional debugging: I copied the generated function to `MatchInstruction.cpp`s and debugged it. In my case the instruction does not seem to require the feature.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to