<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83134>83134</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLVM][CodeGen][InlineAssembly] Invalid inline assembly for subtarget compiles without error.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86,
accepts-invalid,
inline-asm
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
spaits
</td>
</tr>
</table>
<pre>
## 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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVklv4zoS_jX0pWBDoiQvBx8c5yVj4L2ZBibp6VuDEssSpylSw8Wd9K8fkJS32GngBUJoLrV9LH5VzFrRKsQ1qR5I9Thh3nXarO3AhLOTWvP3NaEFoQX8oQ7CaNWjA6H22rDeCa1I9kiyTSOZauGAxoalYgOvtVfOw9U65OUsm2XT3MfNfJaPwoMPIjl1HTyjgp1yKEEspjmdV69A6DKnhK6AlBmUs2WWPf_jV5Ic_yf_XjqEwehaYp_W__zz619Qs-YHKg6saXBwFoSSQiEwa7Gv5TsIZZ3xTQjFguuYA2FBaQfWD4M2DjnU7-A6BOvrqWOmRTeDl05Y6NgwoLKAB1Qg9vEQmWfTXukpKbak2O6ROW8QFOuRFH-Eb57BXrI2WPEWOTgN-DZI0Qgn34ELy2qJUdUoPIMduE6oH2HRINhOe8mhRmDQ6H4QEgGN0QbitkMphWqjBm_RpJjC7CbyAMaBScFnn6BpcDCaJ3BApwCFtR5HfNERugg4HEaPtZT6Z7DeaI7J8ujuT21-gFbwtpxP5yVsv7yOaI8wR_nN12_TKqfHyElxdGmepa8ZhpOTQjXScwRSbIW2ziDrA74XkQjloGdCEbqM6bN4SOsAAFz7gDMj1cOSVI9AisdwIJ9lhG6BpqFIQ5mGKg3zNCzSsJxlZPFIilvV9X3Vf2-4r7r5oPrq3Pk0sz0ctGROSAwYnDbCH6H00OuDHzgQWkWDhFaEVr_6PiPVVpFq6wilv5PKr6Ty30oxzpPQ0cS16OWM3iq6tns8loTorb1iA3dWKO0JpYFPGKGrJH1aqm-XmrB0T03yf7RPk_8Xs2uHgpLbu9lrE0yEFBXxGjNSPMSfW1jGn4Q-xO9D4oY_63h4G8Wm0d5BopqYFCIlRZynIOhV_oQ8SZO7Kk6LqLi847RB542Kro5bR32nF5q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