Skip to content

Commit 01a2efa

Browse files
committed
Merging r168837: into the 3.2 release branch.
Avoid rewriting instructions twice. This could cause miscompilations in targets where sub-register composition is not always idempotent (ARM). <rdar://problem/12758887> git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168849 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0bf2470 commit 01a2efa

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,17 @@ void RegisterCoalescer::updateRegDefsUses(unsigned SrcReg,
850850
// Update LiveDebugVariables.
851851
LDV->renameRegister(SrcReg, DstReg, SubIdx);
852852

853+
SmallPtrSet<MachineInstr*, 8> Visited;
853854
for (MachineRegisterInfo::reg_iterator I = MRI->reg_begin(SrcReg);
854855
MachineInstr *UseMI = I.skipInstruction();) {
856+
// Each instruction can only be rewritten once because sub-register
857+
// composition is not always idempotent. When SrcReg != DstReg, rewriting
858+
// the UseMI operands removes them from the SrcReg use-def chain, but when
859+
// SrcReg is DstReg we could encounter UseMI twice if it has multiple
860+
// operands mentioning the virtual register.
861+
if (SrcReg == DstReg && !Visited.insert(UseMI))
862+
continue;
863+
855864
SmallVector<unsigned,8> Ops;
856865
bool Reads, Writes;
857866
tie(Reads, Writes) = UseMI->readsWritesVirtualRegister(SrcReg, &Ops);

test/CodeGen/ARM/coalesce-subregs.ll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,44 @@ if.end4: ; preds = %if.else3, %if.then2
317317
store <2 x i64> %result.2, <2 x i64>* %agg.result, align 128
318318
ret void
319319
}
320+
321+
; <rdar://problem/12758887>
322+
; RegisterCoalescer::updateRegDefsUses() could visit an instruction more than
323+
; once under rare circumstances. When widening a register from QPR to DTriple
324+
; with the original virtual register in dsub_1_dsub_2, the double rewrite would
325+
; produce an invalid sub-register.
326+
;
327+
; This is because dsub_1_dsub_2 is not an idempotent sub-register index.
328+
; It will translate %vr:dsub_0 -> %vr:dsub_1.
329+
define hidden fastcc void @radar12758887() nounwind optsize ssp {
330+
entry:
331+
br i1 undef, label %for.body, label %for.end70
332+
333+
for.body: ; preds = %for.end, %entry
334+
br i1 undef, label %for.body29, label %for.end
335+
336+
for.body29: ; preds = %for.body29, %for.body
337+
%0 = load <2 x double>* null, align 1
338+
%splat40 = shufflevector <2 x double> %0, <2 x double> undef, <2 x i32> zeroinitializer
339+
%mul41 = fmul <2 x double> undef, %splat40
340+
%add42 = fadd <2 x double> undef, %mul41
341+
%splat44 = shufflevector <2 x double> %0, <2 x double> undef, <2 x i32> <i32 1, i32 1>
342+
%mul45 = fmul <2 x double> undef, %splat44
343+
%add46 = fadd <2 x double> undef, %mul45
344+
br i1 undef, label %for.end, label %for.body29
345+
346+
for.end: ; preds = %for.body29, %for.body
347+
%accumR2.0.lcssa = phi <2 x double> [ zeroinitializer, %for.body ], [ %add42, %for.body29 ]
348+
%accumI2.0.lcssa = phi <2 x double> [ zeroinitializer, %for.body ], [ %add46, %for.body29 ]
349+
%1 = shufflevector <2 x double> %accumI2.0.lcssa, <2 x double> undef, <2 x i32> <i32 1, i32 0>
350+
%add58 = fadd <2 x double> undef, %1
351+
%mul61 = fmul <2 x double> %add58, undef
352+
%add63 = fadd <2 x double> undef, %mul61
353+
%add64 = fadd <2 x double> undef, %add63
354+
%add67 = fadd <2 x double> undef, %add64
355+
store <2 x double> %add67, <2 x double>* undef, align 1
356+
br i1 undef, label %for.end70, label %for.body
357+
358+
for.end70: ; preds = %for.end, %entry
359+
ret void
360+
}

0 commit comments

Comments
 (0)