[SLPVectorizer][OpaquePtrs] Check GEP source element type

Fixes a miscompile with opaque pointers.

Reviewed By: #opaque-pointers, nikic

Differential Revision: https://reviews.llvm.org/D119980
This commit is contained in:
Arthur Eubanks 2022-02-16 14:30:51 -08:00
parent 4e24397805
commit 826fae51d2
2 changed files with 6 additions and 6 deletions

View File

@ -4274,9 +4274,9 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
// We can't combine several GEPs into one vector if they operate on
// different types.
Type *Ty0 = VL0->getOperand(0)->getType();
Type *Ty0 = cast<GEPOperator>(VL0)->getSourceElementType();
for (Value *V : VL) {
Type *CurTy = cast<Instruction>(V)->getOperand(0)->getType();
Type *CurTy = cast<GEPOperator>(V)->getSourceElementType();
if (Ty0 != CurTy) {
LLVM_DEBUG(dbgs()
<< "SLP: not-vectorizable GEP (different types).\n");

View File

@ -6,12 +6,12 @@ target triple = "x86_64-unknown-linux-gnu"
define void @test(ptr %arg, ptr %arg1, ptr %arg2) {
; CHECK-LABEL: @test(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x ptr> poison, ptr [[ARG1:%.*]], i32 0
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x ptr> [[TMP1]], ptr [[ARG2:%.*]], i32 1
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr ptr, <2 x ptr> [[TMP2]], <2 x i64> <i64 -1, i64 128>
; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds i8, ptr [[ARG2:%.*]], i64 128
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds ptr, ptr [[ARG1:%.*]], i64 -1
; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds ptr, ptr [[ARG:%.*]], i64 0
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds ptr, ptr [[ARG]], i64 1
; CHECK-NEXT: store <2 x ptr> [[TMP3]], ptr [[TMP4]], align 8
; CHECK-NEXT: store ptr [[TMP3]], ptr [[TMP4]], align 8
; CHECK-NEXT: store ptr [[TMP]], ptr [[TMP5]], align 8
; CHECK-NEXT: ret void
;
%tmp = getelementptr inbounds i8, ptr %arg2, i64 128