[llvm] [InstCombine] Prevent crash when folding struct-returning ops into vector selects (PR #173208)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 21 19:32:50 PST 2025
https://github.com/Michael-Chen-NJU created https://github.com/llvm/llvm-project/pull/173208
This patch adds a safety check to` FoldOpIntoSelect `to prevent an invalid transformation where an operation returning a struct type is folded into a vector select.
LLVM's SelectInst does not support selecting between two struct operands when the condition is a vector. This logic error is currently latent on main because no struct-returning intrinsics are marked as trivially vectorizable.
This was verified using the existing test `llvm/test/Transforms/InstCombine/select_frexp.ll`.
By temporarily marking llvm.frexp as vectorizable (as proposed in #112408), this existing test triggers an assertion failure in SelectInst::Create.
This patch ensures the test passes (by skipping the invalid fold) even when frexp vectorization is enabled.
>From 8b1a0de1cfbcbb5f96695a1fb3bf2f13def94d65 Mon Sep 17 00:00:00 2001
From: Michael-Chen-NJU <2802328816 at qq.com>
Date: Mon, 22 Dec 2025 11:25:25 +0800
Subject: [PATCH] [InstCombine] Prevent crash when folding struct-returning ops
into vector selects
---
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 14244236d75d5..a339ada97c7e8 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1782,6 +1782,9 @@ static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
bool FoldWithMultiUse,
bool SimplifyBothArms) {
+ if (SI->getCondition()->getType()->isVectorTy() &&
+ !Op.getType()->isVectorTy())
+ return nullptr;
// Don't modify shared select instructions unless set FoldWithMultiUse
if (!SI->hasOneUse() && !FoldWithMultiUse)
return nullptr;
More information about the llvm-commits
mailing list