llvm.org GIT mirror llvm / 17611b1
Merging r247128: ------------------------------------------------------------------------ r247128 | dsanders | 2015-09-09 10:53:20 +0100 (Wed, 09 Sep 2015) | 31 lines Fix vector splitting for extract_vector_elt and vector elements of <8-bits. Summary: One of the vector splitting paths for extract_vector_elt tries to lower: define i1 @via_stack_bug(i8 signext %idx) { %1 = extractelement <2 x i1> <i1 false, i1 true>, i8 %idx ret i1 %1 } to: define i1 @via_stack_bug(i8 signext %idx) { %base = alloca <2 x i1> store <2 x i1> <i1 false, i1 true>, <2 x i1>* %base %2 = getelementptr <2 x i1>, <2 x i1>* %base, i32 %idx %3 = load i1, i1* %2 ret i1 %3 } However, the elements of <2 x i1> are not byte-addressible. The result of this is that the getelementptr expands to '%base + %idx * (1 / 8)' which simplifies to '%base + %idx * 0', and then simply '%base' causing all values of %idx to extract element zero. This commit fixes this by promoting the vector elements of <8-bits to i8 before splitting the vector. This fixes a number of test failures in pocl. Reviewers: pekka.jaaskelainen Subscribers: pekka.jaaskelainen, llvm-commits Differential Revision: http://reviews.llvm.org/D12591 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@247539 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Sanders 4 years ago
3 changed file(s) with 39 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
10091009
10101010 // Calculate the element offset and add it to the pointer.
10111011 unsigned EltSize = EltVT.getSizeInBits() / 8; // FIXME: should be ABI size.
1012 assert(EltSize * 8 == EltVT.getSizeInBits() &&
1013 "Converting bits to bytes lost precision");
10121014
10131015 Index = DAG.getNode(ISD::MUL, dl, Index.getValueType(), Index,
10141016 DAG.getConstant(EltSize, dl, Index.getValueType()));
15271527 if (CustomLowerNode(N, N->getValueType(0), true))
15281528 return SDValue();
15291529
1530 // Make the vector elements byte-addressable if they aren't already.
1531 SDLoc dl(N);
1532 EVT EltVT = VecVT.getVectorElementType();
1533 if (EltVT.getSizeInBits() < 8) {
1534 SmallVector ElementOps;
1535 for (unsigned i = 0; i < VecVT.getVectorNumElements(); ++i) {
1536 ElementOps.push_back(DAG.getAnyExtOrTrunc(
1537 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, Vec,
1538 DAG.getConstant(i, dl, MVT::i8)),
1539 dl, MVT::i8));
1540 }
1541
1542 EltVT = MVT::i8;
1543 VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
1544 VecVT.getVectorNumElements());
1545 Vec = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, ElementOps);
1546 }
1547
15301548 // Store the vector to the stack.
1531 EVT EltVT = VecVT.getVectorElementType();
1532 SDLoc dl(N);
15331549 SDValue StackPtr = DAG.CreateStackTemporary(VecVT);
15341550 SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr,
15351551 MachinePointerInfo(), false, false, 0);
0 ; RUN: llc < %s -march=mips -mcpu=mips2 | FileCheck %s -check-prefix=ALL
1
2 ; This test triggered a bug in the vector splitting where the type legalizer
3 ; attempted to extract the element with by storing the vector, then reading
4 ; an element back. However, the address calculation was:
5 ; Base + Index * (EltSizeInBits / 8)
6 ; and EltSizeInBits was 1. This caused the index to be forgotten.
7 define i1 @via_stack_bug(i8 signext %idx) {
8 %1 = extractelement <2 x i1> , i8 %idx
9 ret i1 %1
10 }
11
12 ; ALL-LABEL: via_stack_bug:
13 ; ALL-DAG: addiu [[ONE:\$[0-9]+]], $zero, 1
14 ; ALL-DAG: sb [[ONE]], 7($sp)
15 ; ALL-DAG: sb $zero, 6($sp)
16 ; ALL-DAG: addiu [[VPTR:\$[0-9]+]], $sp, 6
17 ; ALL-DAG: addu [[EPTR:\$[0-9]+]], $4, [[VPTR]]
18 ; ALL: lbu $2, 0([[EPTR]])