[llvm] [InferAlignment] Increase alignment in masked load / store instrinsics if known (PR #156057)

Alexander Kornienko via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 03:45:27 PDT 2025


alexfh wrote:

@jhuber6 I came up with a reduced test case: https://gcc.godbolt.org/z/Pvffo4e8G

```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define <2 x double> @quux() #0 {
bb:
  %call = call <2 x i64> @snork()
  %call1 = call <2 x double> @hoge(<2 x i64> %call)
  ret <2 x double> %call1
}

define <2 x double> @hoge(<2 x i64> %arg) #0 {
bb:
  %call = call <2 x double> @llvm.x86.avx.maskload.pd(ptr null, <2 x i64> %arg)
  ret <2 x double> %call
}

define <2 x i64> @snork() {
bb:
  %call = call <2 x i64> @hoge.1()
  %call1 = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %call)
  ret <2 x i64> %call1
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: read)
declare <2 x double> @llvm.x86.avx.maskload.pd(ptr, <2 x i64>) #1

define <2 x i64> @hoge.1() {
bb:
  %call = call <2 x i64> @blam(i64 -1)
  ret <2 x i64> %call
}

define <2 x i64> @blam(i64 %arg) {
bb:
  %insertelement = insertelement <2 x i64> zeroinitializer, i64 %arg, i64 0
  ret <2 x i64> %insertelement
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>) #2

attributes #0 = { "target-features"="+avx" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

```
masked_load: alignment must be a power of 2
  %call.i = tail call <2 x double> @llvm.masked.load.v2f64.p0(ptr null, i32 0, <2 x i1> <i1 true, i1 false>, <2 x double> <double poison, double 0.000000e+00>)
in function quux
fatal error: error in backend: Broken function found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -x ir -O3 <source>
1.	Code generation
2.	Running pass 'Function Pass Manager' on module '<source>'.
3.	Running pass 'Module Verifier' on function '@quux'
 #0 0x0000000004193688 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4193688)
 #1 0x0000000004190ab4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4190ab4)
 #2 0x00000000040d5586 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40d5586)
 #3 0x0000000004187f5e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4187f5e)
 #4 0x0000000000db73a0 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x00000000040e02e3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40e02e3)
 #6 0x00000000040e0441 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40e0441)
 #7 0x0000000003b513e2 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) Verifier.cpp:0:0
 #8 0x0000000003a9a648 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9a648)
 #9 0x0000000003a9a881 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9a881)
#10 0x0000000003a9b0ef llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a9b0ef)
#11 0x000000000444a95e clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x444a95e)
#12 0x0000000004ace6a7 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ace6a7)
#13 0x0000000004db9485 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4db9485)
#14 0x0000000004d3535e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d3535e)
#15 0x0000000004eaedcd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eaedcd)
#16 0x0000000000db9b00 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb9b00)
#17 0x0000000000db062a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#18 0x0000000000db07ad int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#19 0x0000000004b36e59 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#20 0x00000000040d54c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40d54c4)
#21 0x0000000004b3746f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#22 0x0000000004af88a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4af88a2)
#23 0x0000000004af984e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4af984e)
#24 0x0000000004b00f75 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b00f75)
#25 0x0000000000db6001 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb6001)
#26 0x0000000000c67d44 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc67d44)
#27 0x000077384da29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x000077384da29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x0000000000db00c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb00c5)
```

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


More information about the llvm-commits mailing list