Skip to content

Commit 85e31ed

Browse files
committed
[DAGCombiner] Relax an assertion to an early return
The select-of-constants transform was asserting that its constant vector inputs did not implicitly truncate their input without that as an explicit precondition to the function. This patch relaxes that assertion into an early return to skip the optimization. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D102393
1 parent a18b5f0 commit 85e31ed

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9224,8 +9224,8 @@ static SDValue foldSelectOfConstantsUsingSra(SDNode *N, SelectionDAG &DAG) {
92249224
SDValue Cond = N->getOperand(0);
92259225
SDValue C1 = N->getOperand(1);
92269226
SDValue C2 = N->getOperand(2);
9227-
assert(isConstantOrConstantVector(C1) && isConstantOrConstantVector(C2) &&
9228-
"Expected select-of-constants");
9227+
if (!isConstantOrConstantVector(C1) || !isConstantOrConstantVector(C2))
9228+
return SDValue();
92299229

92309230
EVT VT = N->getValueType(0);
92319231
if (Cond.getOpcode() != ISD::SETCC || !Cond.hasOneUse() ||
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-v -riscv-v-vector-bits-min=128 -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV32
3+
; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -riscv-v-vector-bits-min=128 -verify-machineinstrs < %s | FileCheck %s --check-prefix=RV64
4+
5+
; This test checks a regression in the select-to-sra transform, which was
6+
; asserting (without a precondition) when the vector constants implicitly
7+
; truncated their inputs, as we do on RV64.
8+
define <4 x i32> @vselect_of_consts(<4 x i1> %cc) {
9+
; RV32-LABEL: vselect_of_consts:
10+
; RV32: # %bb.0:
11+
; RV32-NEXT: lui a0, 284280
12+
; RV32-NEXT: addi a0, a0, 291
13+
; RV32-NEXT: vsetivli a1, 4, e32,m1,ta,mu
14+
; RV32-NEXT: vmv.v.x v25, a0
15+
; RV32-NEXT: lui a0, 214376
16+
; RV32-NEXT: addi a0, a0, -2030
17+
; RV32-NEXT: vmerge.vxm v8, v25, a0, v0
18+
; RV32-NEXT: ret
19+
;
20+
; RV64-LABEL: vselect_of_consts:
21+
; RV64: # %bb.0:
22+
; RV64-NEXT: lui a0, 284280
23+
; RV64-NEXT: addiw a0, a0, 291
24+
; RV64-NEXT: vsetivli a1, 4, e32,m1,ta,mu
25+
; RV64-NEXT: vmv.v.x v25, a0
26+
; RV64-NEXT: lui a0, 214376
27+
; RV64-NEXT: addiw a0, a0, -2030
28+
; RV64-NEXT: vmerge.vxm v8, v25, a0, v0
29+
; RV64-NEXT: ret
30+
%v = select <4 x i1> %cc, <4 x i32> <i32 878082066, i32 878082066, i32 878082066, i32 878082066>, <4 x i32> <i32 1164411171, i32 1164411171, i32 1164411171, i32 1164411171>
31+
ret <4 x i32> %v
32+
}

0 commit comments

Comments
 (0)