<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74307>74307</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM loop-vectorize crash: Assertion `OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
llvm loop-vectorize crashes on the test case.
Bisected to 70535f5e609f747c28cfef699eefb84581b0aac0, which was committed by @fhahn
Compiler explorer: https://godbolt.org/z/xoocPv6qz
```console
% cat a.ll
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 void @h() {
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%cmp = icmp eq i64 1, 1
%conv2 = zext i1 %cmp to i64
%cmp3 = icmp sle i64 0, %conv2
%or = or i64 1, %conv2
%conv6 = trunc i64 %or to i32
store i32 %conv6, ptr null, align 4
%inc = add i32 %0, 1
%tobool.not = icmp eq i32 %inc, 0
br i1 %tobool.not, label %for.cond.for.end_crit_edge, label %for.body
for.cond.for.end_crit_edge: ; preds = %for.body
ret void
}
%
% opt -passes=loop-vectorize < a.ll
opt: /tmp/tmp3fb6wg21/tmp733uaukt/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:914: static void llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, const llvm::MapVector<llvm::Instruction*, long unsigned int>&, llvm::LLVMContext&): Assertion `OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/opt -disable-output -passes=loop-vectorize
#0 0x00007f4d091bf70f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x93770f)
#1 0x00007f4d091bcc34 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f4d0849d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
#3 0x00007f4d0849d00b raise /build/glibc-BHL3KM/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#4 0x00007f4d0847c859 abort /build/glibc-BHL3KM/glibc-2.31/stdlib/abort.c:81:7
#5 0x00007f4d0847c729 get_sysdep_segment_value /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:509:8
#6 0x00007f4d0847c729 _nl_load_domain /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:970:34
#7 0x00007f4d0848dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x00007f4d0ade6bbe llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, llvm::MapVector<llvm::Instruction*, unsigned long, llvm::DenseMap<llvm::Instruction*, unsigned int, llvm::DenseMapInfo<llvm::Instruction*, void>, llvm::detail::DenseMapPair<llvm::Instruction*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Instruction*, unsigned long>, 0u>> const&, llvm::LLVMContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x255ebbe)
#9 0x00007f4d0accabca llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x2442bca)
#10 0x00007f4d0acd20b1 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x244a0b1)
#11 0x00007f4d0acde149 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x2456149)
#12 0x00007f4d0ace137d llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x245937d)
#13 0x00007f4d0ace25d0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x245a5d0)
#14 0x00007f4d0c1199c6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x38919c6)
#15 0x00007f4d093dc0ad llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0xb540ad)
#16 0x00007f4d0c1126b6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x388a6b6)
#17 0x00007f4d093da93d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0xb5293d)
#18 0x00007f4d0c1196f6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0x38916f6)
#19 0x00007f4d093d886d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/../lib/libLLVM-18git.so+0xb5086d)
#20 0x000055eb0abc6395 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/opt+0x26395)
#21 0x000055eb0abb9e8a main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/opt+0x19e8a)
#22 0x00007f4d0847e083 __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:342:3
#23 0x000055eb0abbaa5e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-70535f5e609f747c28cfef699eefb84581b0aac0/bin/opt+0x1aa5e)
[1] 3165813 abort -disable-output -passes=loop-vectorize < a.ll
%
```
This test case is reduced from the following C program:
```console
int a, f;
int *b, *g;
static long c;
static long *d = &c;
long e;
void h() {
for (; f; f++) {
long *i = &c;
long **j[5] = {&i};
b = &a;
*b = (*d <= (e == *g)) | 1 + *d;
}
}
int main() {}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltz46gS_jXkhbILgXV7yIOcxLVTO9lNTVJzHl0IIZkNAi2gXObXnwLJFznOTrLX1Dk75VEENE33x9e0JKDWikZxfg7iJYgvz2jvNtqc2w3Vs01PZ1Kclbp6PpfyoYVS6272wJnTRnzjkBlqN9xCraDbcOi4dZBRy-cAXQJUDNelsJw5XkGnYYpiEtcxT1Bep4uU4YzVvE7ynPO6zBZxFpWIUoYAvoCPG8E28JFayHTbCudVlM8QLFC9oRsFD8e40G0nJDeQP3VSG24AKeDGuc4CUgC8AnjV6KrU0s21aQBefQN49aQ1u3lIfv12qAkkaPgxrayWfKzFMWTUQTqXcqhx1DTcwYo6Kumz7h0E5BICjPmsBaTgsw6nCJCC4HDxxWha9HfJIlxmYncT4QyQIsLZrM7QeKdCVbLtnixmt14M44kpzohO8q0ZT1myThazXt0r_ahmUqj-adaoftdruFa8ForDBy0qj-wGeL05BOlyaOfKmWePYSjB0kBJSy4hwHGtzdwz41Ddro4UEJAl7Ayv7GjSvgO-8MVB9aDXl1GQ6zYCCoIhiJcQHUpCEF-Gcrz0dUKxsXWrNgjs1bG2CwqFv-G_QpEsYOS7RIdCWj3gIPaNPzkoom1Pp32HqTqy12clDwq3FgY9B9LaB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