Skip to content

[DAGCombiner] Don't ignore N2's undef elements in foldVSelectOfConstants #129272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12535,9 +12535,10 @@ SDValue DAGCombiner::foldVSelectOfConstants(SDNode *N) {
for (unsigned i = 0; i != Elts; ++i) {
SDValue N1Elt = N1.getOperand(i);
SDValue N2Elt = N2.getOperand(i);
if (N1Elt.isUndef() || N2Elt.isUndef())
if (N1Elt.isUndef())
continue;
if (N1Elt.getValueType() != N2Elt.getValueType()) {
// N2 should not contain undef values since it will be reused in the fold.
if (N2Elt.isUndef() || N1Elt.getValueType() != N2Elt.getValueType()) {
AllAddOne = false;
AllSubOne = false;
break;
Expand Down
18 changes: 18 additions & 0 deletions llvm/test/CodeGen/X86/vselect-constants.ll
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,21 @@ define i32 @wrong_min_signbits(<2 x i16> %x) {
%t1 = bitcast <2 x i16> %sel to i32
ret i32 %t1
}

define i32 @pr129181() {
; SSE-LABEL: pr129181:
; SSE: # %bb.0: # %entry
; SSE-NEXT: xorl %eax, %eax
; SSE-NEXT: retq
;
; AVX-LABEL: pr129181:
; AVX: # %bb.0: # %entry
; AVX-NEXT: xorl %eax, %eax
; AVX-NEXT: retq
entry:
%x = insertelement <4 x i32> zeroinitializer, i32 0, i32 0
%cmp = icmp ult <4 x i32> %x, splat (i32 1)
%sel = select <4 x i1> %cmp, <4 x i32> zeroinitializer, <4 x i32> <i32 0, i32 0, i32 1, i32 poison>
%reduce = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %sel)
ret i32 %reduce
}
Loading