[llvm] [SLP]Allow bitcast/bswap based reductions for types, larger than the total strided size (PR #184018)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 03:21:51 PDT 2026


Andarwinux wrote:

@alexey-bataev https://llvm.godbolt.org/z/1jd3Wb3vM

-O3 -slp-vectorize-non-power-of-2
```
define i64 @bswap_i24(ptr noalias %p, ptr noalias %p1) {
  %g1 = getelementptr i8, ptr %p, i32 1
  %g2 = getelementptr i8, ptr %p, i32 2

  %t0 = load i8, ptr %p
  %t1 = load i8, ptr %g1
  %t2 = load i8, ptr %g2

  %g11 = getelementptr i8, ptr %p1, i32 1
  %g12 = getelementptr i8, ptr %p1, i32 2

  %t10 = load i8, ptr %p1
  %t11 = load i8, ptr %g11
  %t12 = load i8, ptr %g12

  %a0 = add i8 %t0, %t10
  %a1 = add i8 %t1, %t11
  %a2 = add i8 %t2, %t12

  %z0 = zext i8 %a0 to i64
  %z1 = zext i8 %a1 to i64
  %z2 = zext i8 %a2 to i64

  %sh0 = shl nuw i64 %z0, 16
  %sh1 = shl nuw nsw i64 %z1, 8

  %or01 = or disjoint i64 %sh0, %sh1
  %or012 = or disjoint i64 %or01, %z2

  ret i64 %or012
}
```
```
bswap must be an even number of bytes
  %5 = tail call i24 @llvm.bswap.i24(i24 %4)
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -O3 -slp-vectorize-non-power-of-2 <source>
1.	Running pass "verify" on module "<source>"
 #0 0x0000000005c09b78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5c09b78)
 #1 0x0000000005c069a4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007dc336042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007dc3360969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007dc336042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007dc3360287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x000000000083274b llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0
 #7 0x0000000005b38ef1 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5b38ef1)
 #8 0x00000000059b51f8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59b51f8)
 #9 0x000000000096ee2e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96ee2e)
#10 0x0000000005971a11 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5971a11)
#11 0x000000000097901a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x97901a)
#12 0x000000000096d0b5 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96d0b5)
#13 0x00007dc336029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#14 0x00007dc336029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#15 0x0000000000963d95 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x963d95)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

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


More information about the llvm-commits mailing list