[Scalarizer] Avoid changing name of non-instructions

The "takeName" logic in ScalarizerVisitor::gather did not consider
that the value vector could refer to non-instructions, such as
global variables. This patch make sure that we avoid changing the
name of a value if it isn't an instruction.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D87685
This commit is contained in:
Bjorn Pettersson 2020-09-14 22:53:54 +02:00
parent af3789a188
commit aa8be5aeea
2 changed files with 22 additions and 1 deletions

View File

@ -398,7 +398,8 @@ void ScalarizerVisitor::gather(Instruction *Op, const ValueVector &CV) {
continue; continue;
Instruction *Old = cast<Instruction>(V); Instruction *Old = cast<Instruction>(V);
CV[I]->takeName(Old); if (isa<Instruction>(CV[I]))
CV[I]->takeName(Old);
Old->replaceAllUsesWith(CV[I]); Old->replaceAllUsesWith(CV[I]);
PotentiallyDeadInstrs.emplace_back(Old); PotentiallyDeadInstrs.emplace_back(Old);
} }

View File

@ -0,0 +1,20 @@
; RUN: opt < %s -scalarizer -S -o - | FileCheck %s
; RUN: opt < %s -passes='function(scalarizer)' -S | FileCheck %s
; The scalarizer used to change the name of the global variable
; Check that the we don't do that any longer.
;
; CHECK: @c.a = global i16 0, align 1
@c.a = global i16 0, align 1
define void @c() {
entry:
br label %for.cond1
for.cond1: ; preds = %for.cond1, %entry
%d.sroa.0.0 = phi <4 x i16*> [ <i16* @c.a, i16* @c.a, i16* @c.a, i16* @c.a>, %entry ], [ %d.sroa.0.1.vec.insert, %for.cond1 ]
%d.sroa.0.0.vec.extract = extractelement <4 x i16*> %d.sroa.0.0, i32 0
%d.sroa.0.1.vec.insert = shufflevector <4 x i16*> <i16* @c.a, i16* null, i16* undef, i16* undef>, <4 x i16*> %d.sroa.0.0, <4 x i32> <i32 0, i32 1, i32 6, i32 7>
br label %for.cond1
}