Skip to content

Commit a668846

Browse files
authored
[DAGCombiner] Handle extending EXTRACT_VECTOR_ELTs in calculateByteProvider (#83963)
An EXTRACT_VECTOR_ELT can extend the element to the width of its result type, leaving the high bits undefined. Previously if we attempted to query the bytes in these high bits we would recurse and hit an assertion. This fixes it by bailing if the index is outside of the vector element size. I think the assertion Index < ByteWidth may still be incorrect, since ByteWidth is calculated from Op.getValueSizeInBits(). I believe this should be Op.getScalarValueSizeInBits() whenever VectorIndex is set since we're querying the element now, not the vector. But I couldn't think of a test case to trigger it. It can be addressed in a follow-up patch. Fixes #83920
1 parent b585c43 commit a668846

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8627,6 +8627,10 @@ calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth,
86278627
if (NarrowBitWidth % 8 != 0)
86288628
return std::nullopt;
86298629
uint64_t NarrowByteWidth = NarrowBitWidth / 8;
8630+
// EXTRACT_VECTOR_ELT can extend the element type to the width of the return
8631+
// type, leaving the high bits undefined.
8632+
if (Index >= NarrowByteWidth)
8633+
return std::nullopt;
86308634

86318635
// Check to see if the position of the element in the vector corresponds
86328636
// with the byte we are trying to provide for. In the case of a vector of
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v | FileCheck %s
3+
4+
define i8 @or_load_combine(ptr %p) {
5+
; CHECK-LABEL: or_load_combine:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: vsetivli zero, 2, e8, mf8, ta, ma
8+
; CHECK-NEXT: vle8.v v8, (a0)
9+
; CHECK-NEXT: vmv.x.s a0, v8
10+
; CHECK-NEXT: ori a0, a0, 1
11+
; CHECK-NEXT: ret
12+
%load = load <2 x i8>, ptr %p
13+
%extract = extractelement <2 x i8> %load, i64 0
14+
%or = or i8 %extract, 1
15+
ret i8 %or
16+
}

0 commit comments

Comments
 (0)