Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm missing static address offset in some cases. #55482

Open
ottoville opened this issue May 15, 2022 · 2 comments
Open

Wasm missing static address offset in some cases. #55482

ottoville opened this issue May 15, 2022 · 2 comments

Comments

@ottoville
Copy link

ottoville commented May 15, 2022

llvm fails to add static offset address to memory load instructions in some cases.

Here is godbold link that demonstrates the issue:
https://godbolt.org/z/c6oPfehfo
The function get_YY should load value from memory address having static offset of 20, like all other functions in example.
Instead, it adds 20 to existing memory address by arithmetic operator.
All other load instructions that have offset less than 20 are using static offset as seen in godbold output.

The llvm code itself is correct:

define hidden float @_ZN7example6get_YY17h71095c69e6bab6acE(%"Vec4<Vec4<f32>>"* noalias nocapture noundef readonly align 4 dereferenceable(64) %v) unnamed_addr #0 !dbg !23 {
  %0 = getelementptr inbounds %"Vec4<Vec4<f32>>", %"Vec4<Vec4<f32>>"* %v, i32 0, i32 1, i32 1, !dbg !24
  %1 = load float, float* %0, align 4, !dbg !24
  ret float %1, !dbg !25
}

Link to llvm output: https://godbolt.org/z/z4ehToarG

When same struct is refactored to have five component, it works on offset 20, but does not work on offset 24. So it seems problem is always from the second component on second vector.
https://godbolt.org/z/Meq858KWq

The issue occurs only when targeting to WASM, the X86 instructions are fine https://godbolt.org/z/sx67bW7dv

@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2023

@llvm/issue-subscribers-backend-webassembly

llvm fails to add static offset address to memory load instructions in some cases.

Here is godbold link that demonstrates the issue:
https://godbolt.org/z/47PbT4669
The function get_YY should load value from memory address having static offset of 20, like all other functions in example.
Instead, it adds 20 to existing memory address by arithmetic operator.
All other load instructions that have offset less than 20 are using static offset as seen in godbold output.

The llvm code itself is correct:

define hidden float @<!-- -->_ZN7example6get_YY17h71095c69e6bab6acE(%"Vec4&lt;Vec4&lt;f32&gt;&gt;"* noalias nocapture noundef readonly align 4 dereferenceable(64) %v) unnamed_addr #<!-- -->0 !dbg !23 {
  %0 = getelementptr inbounds %"Vec4&lt;Vec4&lt;f32&gt;&gt;", %"Vec4&lt;Vec4&lt;f32&gt;&gt;"* %v, i32 0, i32 1, i32 1, !dbg !24
  %1 = load float, float* %0, align 4, !dbg !24
  ret float %1, !dbg !25
}

Link to llvm output: https://godbolt.org/z/z4ehToarG

When same struct is refactored to have five component, it works on offset 20, but does not work on offset 24. So it seems problem is always from the second component on second vector.
https://godbolt.org/z/Meq858KWq

The issue occurs only when targeting to WASM, the X86 instructions are fine https://godbolt.org/z/sx67bW7dv

@ottoville
Copy link
Author

ottoville commented Apr 12, 2024

The issue can no longer be reproduced in rust beta https://godbolt.org/z/o77hnz8b8
Must be because LLVM has been updated to v18 rust-lang/rust#120055

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants