[llvm-dev] Problem with BranchFolder::OptimizeImpDefsBlock

Krzysztof Parzyszek via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 6 09:09:48 PDT 2016


This function removes implicit defs from blocks that have no other 
non-branch instructions, and where the registers defined in those 
implicit defs are not used by the branches.  This creates a problem if 
the registers are actually live-in in some successor blocks.

Dead implicit defs should have been deleted by the time this code runs, 
and non-dead implicit defs should not be removed.  I think this function 
should be deleted, but I'm wondering if anyone else has different ideas.

Below is a testcase and the outcome.

-Krzysztof


--- bug.ll ---
target triple = "hexagon"

define void @fred(i32 %p0) local_unnamed_addr align 2 {
b0:
   br i1 undef, label %b1, label %b2

b1:                                               ; preds = %b0
   %t0 = load i8*, i8** undef, align 4
   br label %b2

b2:                                               ; preds = %b1, %b0
   %t1 = phi i8* [ %t0, %b1 ], [ undef, %b0 ]
   %t2 = getelementptr inbounds i8, i8* %t1, i32 %p0
   tail call void @llvm.memmove.p0i8.p0i8.i32(i8* undef, i8* %t2, i32 
undef, i32 1, i1 false) #1
   unreachable
}

declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture 
readonly, i32, i32, i1) #0

attributes #0 = { argmemonly nounwind }
attributes #1 = { nounwind }
--------------


llc -march=hexagon < bug.ll -verify-machineinstrs

         .text
         .file   "<stdin>"

# After Hexagon Split Const32s and Const64s
# Machine code for function fred: NoPHIs, TracksLiveness, NoVRegs
Function Live Ins: %R0

BB#0: derived from LLVM BB %b0
     Live Ins: %R0
         %R1<def> = L2_ploadrif_io %P0<undef>, %R0<undef>, 0, 
%R1<imp-use>; mem:LD4[undef]
         S2_allocframe 0, %R29<imp-def>, %R30<imp-def>, %R29<imp-use>, 
%R31<imp-use>, %R30<imp-use>; mem:ST4[<unknown>]
         %R1<def> = A2_add %R1<kill>, %R0<kill>
         J2_call <es:memmove>, %D0<imp-def,dead>, %D1<imp-def,dead>, 
%R31<imp-def,dead>, %P0<imp-def,dead>, %R0<imp-use,undef>, %R1<imp-use>, 
%R2<imp-use,undef>, ...
         L2_deallocframe %R29<imp-def>, %R30<imp-def>, %R31<imp-def>, 
%R30<imp-use>

# End machine code for function fred.

*** Bad machine code: Using an undefined physical register ***
- function:    fred
- basic block: BB#0 b0 (0x4bb1788)
- instruction: %R1<def> = L2_ploadrif_io
- operand 4:   %R1<imp-use>
LLVM ERROR: Found 1 machine code errors.




-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, 
hosted by The Linux Foundation


More information about the llvm-dev mailing list