[InstCombine][InstCombineVectorOps] crash after 0aa9ec6a36 (fold zext into de-interleaving)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Just a small missed case in an optimization. This showed up while building gcc with our branch.
```
commit 0aa9ec6a361002f54deb2a8036410455ee527950
Author: Min-Yih Hsu
Date: Thu May 28 10:34:22 2026 -0700
[InstCombine] Fold zext into de-interleaving (factor=2) instructions (#195330)
```
https://godbolt.org/z/haE4effrE
```llvm
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"
@global.1 = constant [27 x [2 x i32]] [[2 x i32] zeroinitializer, [2 x i32] [i32 1, i32 0], [2 x i32] [i32 2, i32 0], [2 x i32] [i32 4, i32 0], [2 x i32] [i32 8, i32 0], [2 x i32] [i32 16, i32 0], [2 x i32] [i32 32, i32 0], [2 x i32] [i32 3, i32 0], [2 x i32] [i32 7, i32 0], [2 x i32] [i32 15, i32 0], [2 x i32] [i32 1114352, i32 8160], [2 x i32] [i32 127, i32 8160], [2 x i32] [i32 1114367, i32 0], [2 x i32] [i32 1114367, i32 8160], [2 x i32] [i32 256, i32 0], [2 x i32] [i32 512, i32 0], [2 x i32] [i32 65280, i32 0], [2 x i32] [i32 2097152, i32 0], [2 x i32] [i32 534773760, i32 2088960], [2 x i32] [i32 -536870912, i32 31], [2 x i32] [i32 534774016, i32 2088960], [2 x i32] [i32 534774272, i32 2088960], [2 x i32] [i32 534839040, i32 4186112], [2 x i32] [i32 131071, i32 8160], [2 x i32] [i32 534839551, i32 2097120], [2 x i32] [i32 534904831, i32 2097120], [2 x i32] [i32 -1, i32 2097151]]
define void @wobble(ptr %global) {
bb:
br label %bb1
bb1: ; preds = %bb1, %bb
%phi1 = phi i64 [ 0, %bb ], [ %add, %bb1 ]
%getelementptr = getelementptr [27 x [2 x i32]], ptr @global.1, i64 0, i64 %phi1, i64 0
%load = load <32 x i32>, ptr %getelementptr, align 8
%shufflevector = shufflevector <32 x i32> %load, <32 x i32> zeroinitializer, <16 x i32>
%shufflevector2 = shufflevector <32 x i32> %load, <32 x i32> zeroinitializer, <16 x i32>
%and3 = and <16 x i32> %shufflevector2, splat (i32 32)
%icmp4 = icmp ne <16 x i32> %and3, zeroinitializer
%and = and <16 x i32> %shufflevector, splat (i32 -2147483648)
%icmp = icmp ne <16 x i32> %and, zeroinitializer
%select = select <16 x i1> %icmp, <16 x i64> splat (i64 1), <16 x i64> zeroinitializer
%or = or <16 x i64> %select, splat (i64 137438953472)
%and6 = and <16 x i32> %shufflevector2, splat (i32 64)
%icmp7 = icmp ne <16 x i32> %and6, zeroinitializer
%select5 = select <16 x i1> %icmp4, <16 x i64> %or, <16 x i64> zeroinitializer
%or8 = or <16 x i64> %select5, splat (i64 274877906944)
%select9 = select <16 x i1> %icmp7, <16 x i64> %or8, <16 x i64> %select5
%or12 = or <16 x i64> %select9, splat (i64 549755813888)
%or16 = or <16 x i64> %or12, splat (i64 1099511627776)
%or20 = or <16 x i64> %or16, splat (i64 2199023255552)
%or24 = or <16 x i64> %or20, splat (i64 4398046511104)
%or28 = or <16 x i64> %or24, splat (i64 8796093022208)
%or32 = or <16 x i64> %or28, splat (i64 17592186044416)
store <16 x i64> %or32, ptr %global, align 16
%add = or i64 %phi1, 0
br label %bb1
}
```
Suggested fix:
```
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 86f64363d418..6993401da830 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -3393,6 +3393,8 @@ InstCombinerImpl::foldExtractionOfVectorDeinterleave(ZExtInst &RootZExt) {
return nullptr;
}
+ if (isa(DIV))
+ return nullptr;
auto *InputVecTy = dyn_cast(DIV->getType());
if (!InputVecTy)
return nullptr;
```
Contributor guide
Assessment
This issue has not been assessed yet.