[llvm] [DenseMap] Optimize find/erase (PR #100517)

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 13:21:35 PDT 2024


aganea wrote:

This is caused by miscompilation in latest MSVC. I'm using latest version available: `Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33813 for x64`.

As seen in the previous message, the symptom is that a bad alignement is generated in one of the load instructions:
```
huge alignment values are unsupported
  %2 = load i64, ptr %1, align 9223372036854775808
```
When `Builder.CreateLoad` is called [here](https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGObjCGNU.cpp#L2096), somehow [this call](https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGBuilder.h#L110) to `Addr.getAlignment().getAsAlign()` returns a bad alignement. The problem occurs at the highlighted line (`sub bh,cl`):

![Screenshot 2024-08-09 154835](https://github.com/user-attachments/assets/8a45973b-d75c-4e0d-a74a-ae49bb3f01d5)

The code on the right is translated to the assembly on the right.  `llvm::count_zero` returns a proper value (as seen in RCX), however `sub bh, cl` uses a bad constant in `bh` (it is not 63 as expected). I think the optimizer meant to use `dil` not `bh`. A few lines below it does `mov byte ptr [rsp + 40h], dil`. If I manually set `6` in RDI after `sub` is executed, as it should have been, the test passes.

It's a tad scary, but just shuffling around the lines of code in `CGObjCGNU.cpp` fixes the issue. I'll send out a PR and will fill a bug report with Microsoft.

https://github.com/llvm/llvm-project/pull/100517


More information about the llvm-commits mailing list