[llvm] [X86] Match ENDBR immediates in little-endian order (PR #208754)
Phoebe Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 20:31:55 PDT 2026
================
@@ -926,22 +926,30 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) {
}
}
-static bool isEndbrImm64(uint64_t Imm) {
-// There may be some other prefix bytes between 0xF3 and 0x0F1EFA.
-// i.g: 0xF3660F1EFA, 0xF3670F1EFA
- if ((Imm & 0x00FFFFFF) != 0x0F1EFA)
+static bool isEndbrImm(uint64_t Imm, unsigned BitWidth) {
+ assert(BitWidth <= 64 && BitWidth % 8 == 0 && "Unexpected immediate size");
+
+ const unsigned NumBytes = BitWidth / 8;
+ if (NumBytes < 4)
return false;
- uint8_t OptionalPrefixBytes [] = {0x26, 0x2e, 0x36, 0x3e, 0x64,
- 0x65, 0x66, 0x67, 0xf0, 0xf2};
- int i = 24; // 24bit 0x0F1EFA has matched
- while (i < 64) {
- uint8_t Byte = (Imm >> i) & 0xFF;
- if (Byte == 0xF3)
+ const uint8_t OptionalPrefixBytes[] = {0x26, 0x2e, 0x36, 0x3e, 0x64,
+ 0x65, 0x66, 0x67, 0xf0, 0xf2};
+ uint8_t Bytes[8];
+ for (unsigned I = 0; I != NumBytes; ++I)
+ Bytes[I] = (Imm >> (I * 8)) & 0xFF;
+
+ for (unsigned I = 0; I + 3 < NumBytes; ++I) {
+ if (Bytes[I] != 0xf3)
+ continue;
+
+ unsigned J = I + 1;
+ while (J < NumBytes && llvm::is_contained(OptionalPrefixBytes, Bytes[J]))
----------------
phoebewang wrote:
Lack tests for optional prefix.
https://github.com/llvm/llvm-project/pull/208754
More information about the llvm-commits
mailing list