Skip to content

Commit 3969d2c

Browse files
committed
[InstCombine] Disable select known bits fold for vectors
This is not safe if the simplification ends up looking through lane-crossing operations. For now, we don't have a good way to limit this in computeKnownBits(), so just disable vector handling entirely. Fixes #97475.
1 parent b77e734 commit 3969d2c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4049,7 +4049,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
40494049
if (CondVal->getType() == SI.getType() && isKnownInversion(FalseVal, TrueVal))
40504050
return BinaryOperator::CreateXor(CondVal, FalseVal);
40514051

4052-
if (SelType->isIntOrIntVectorTy() &&
4052+
// For vectors, this transform is only safe if the simplification does not
4053+
// look through any lane-crossing operations. For now, limit to scalars only.
4054+
if (SelType->isIntegerTy() &&
40534055
(!isa<Constant>(TrueVal) || !isa<Constant>(FalseVal))) {
40544056
// Try to simplify select arms based on KnownBits implied by the condition.
40554057
CondContext CC(CondVal);

llvm/test/Transforms/InstCombine/select-binop-cmp.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,10 @@ define <2 x i8> @select_xor_icmp_vec_bad(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z)
571571

572572
define <2 x i32> @vec_select_no_equivalence(<2 x i32> %x) {
573573
; CHECK-LABEL: @vec_select_no_equivalence(
574-
; CHECK-NEXT: ret <2 x i32> [[X:%.*]]
574+
; CHECK-NEXT: [[X10:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
575+
; CHECK-NEXT: [[COND:%.*]] = icmp eq <2 x i32> [[X]], zeroinitializer
576+
; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[COND]], <2 x i32> [[X10]], <2 x i32> [[X]]
577+
; CHECK-NEXT: ret <2 x i32> [[S]]
575578
;
576579
%x10 = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> <i32 1, i32 0>
577580
%cond = icmp eq <2 x i32> %x, zeroinitializer

0 commit comments

Comments
 (0)