[PATCH] R600/SI: Fix crash in SIAnnotateControlFlow

Matt Arsenault Matthew.Arsenault at amd.com
Fri Feb 6 11:06:59 PST 2015


On 02/06/2015 07:41 AM, Tom Stellard wrote:
> When analyzing PHI loop conditions, we should handle undef values the same
> as constants.
> ---
>   lib/Target/R600/SIAnnotateControlFlow.cpp |  2 +-
>   test/CodeGen/R600/si-annotate-cf-crash.ll | 62 +++++++++++++++++++++++++++++++
>   2 files changed, 63 insertions(+), 1 deletion(-)
>   create mode 100644 test/CodeGen/R600/si-annotate-cf-crash.ll

I don't see where the undef comes from in the test? I think the test 
name should also include undef
>
> diff --git a/lib/Target/R600/SIAnnotateControlFlow.cpp b/lib/Target/R600/SIAnnotateControlFlow.cpp
> index 79f6532..a780171 100644
> --- a/lib/Target/R600/SIAnnotateControlFlow.cpp
> +++ b/lib/Target/R600/SIAnnotateControlFlow.cpp
> @@ -217,7 +217,7 @@ Value *SIAnnotateControlFlow::handleLoopCondition(Value *Cond, PHINode *Broken)
>       for (unsigned i = 0, e = Phi->getNumIncomingValues(); i != e; ++i) {
>         Value *Incoming = Phi->getIncomingValue(i);
>         BasicBlock *From = Phi->getIncomingBlock(i);
> -      if (isa<ConstantInt>(Incoming)) {
> +      if (isa<ConstantInt>(Incoming) || isa<UndefValue>(Incoming)) {
>           NewPhi->addIncoming(Broken, From);
>           continue;
>         }
> diff --git a/test/CodeGen/R600/si-annotate-cf-crash.ll b/test/CodeGen/R600/si-annotate-cf-crash.ll
> new file mode 100644
> index 0000000..a9f1835
> --- /dev/null
> +++ b/test/CodeGen/R600/si-annotate-cf-crash.ll
> @@ -0,0 +1,62 @@
> +; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs-asm < %s | FileCheck %s
> +; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck %s
> +
> +; CHECK-LABEL: {{^}}test:
> +; CHECK: s_endpgm
> +define void @test(float addrspace(1)* nocapture %arg, i32 %arg1, float addrspace(1)* nocapture readonly %arg2, float %arg3) {
> +bb:
> +  br label %bb3
> +
> +bb3:                                              ; preds = %bb36, %bb
> +  %tmp = phi i64 [ %tmp39, %bb36 ], [ 1, %bb ]
> +  %tmp4 = phi float [ %tmp38, %bb36 ], [ 5.000000e+01, %bb ]
> +  %tmp5 = phi i32 [ %tmp28, %bb36 ], [ 0, %bb ]
> +  %tmp6 = phi i32 [ %tmp37, %bb36 ], [ 0, %bb ]
> +  %tmp7 = trunc i64 %tmp to i32
> +  %tmp8 = icmp eq i32 %tmp7, %arg1
> +  br i1 %tmp8, label %bb26, label %bb9
> +
> +bb9:                                              ; preds = %bb18, %bb3
> +  %tmp10 = phi i32 [ %tmp20, %bb18 ], [ %tmp7, %bb3 ]
> +  %tmp11 = phi i64 [ %tmp19, %bb18 ], [ %tmp, %bb3 ]
> +  %tmp12 = getelementptr inbounds float addrspace(1)* %arg2, i64 %tmp11
> +  %tmp13 = load float addrspace(1)* %tmp12, align 4
> +  %tmp17 = fcmp une float %tmp13, %arg3
> +  br i1 %tmp17, label %bb22, label %bb18
> +
> +bb18:                                             ; preds = %bb9
> +  %tmp19 = add nuw nsw i64 %tmp11, 1
> +  %tmp20 = trunc i64 %tmp19 to i32
> +  %tmp21 = icmp eq i32 %tmp20, %arg1
> +  br i1 %tmp21, label %bb22, label %bb9
> +
> +bb22:                                             ; preds = %bb18, %bb9
> +  %tmp23 = phi i1 [ false, %bb9 ], [ true, %bb18 ]
> +  %tmp24 = phi i32 [ %tmp10, %bb9 ], [ %arg1, %bb18 ]
> +  %tmp25 = phi i64 [ %tmp11, %bb9 ], [ %tmp19, %bb18 ]
> +  br label %bb26
> +
> +bb26:                                             ; preds = %bb22, %bb3
> +  %tmp27 = phi i1 [ true, %bb3 ], [ %tmp23, %bb22 ]
> +  %tmp28 = phi i32 [ %arg1, %bb3 ], [ %tmp24, %bb22 ]
> +  %tmp29 = phi i64 [ %tmp, %bb3 ], [ %tmp25, %bb22 ]
> +  %tmp30 = sub nsw i32 %tmp28, %tmp5
> +  %tmp31 = icmp slt i32 %tmp6, %tmp30
> +  br i1 %tmp31, label %bb32, label %bb36
> +
> +bb32:                                             ; preds = %bb26
> +  %tmp33 = add nsw i64 %tmp29, -1
> +  %tmp34 = getelementptr inbounds float addrspace(1)* %arg2, i64 %tmp33
> +  %tmp35 = load float addrspace(1)* %tmp34, align 4
> +  br label %bb36
> +
> +bb36:                                             ; preds = %bb32, %bb26
> +  %tmp37 = phi i32 [ %tmp30, %bb32 ], [ %tmp6, %bb26 ]
> +  %tmp38 = phi float [ %tmp35, %bb32 ], [ %tmp4, %bb26 ]
> +  %tmp39 = add nuw nsw i64 %tmp29, 1
> +  br i1 %tmp27, label %bb40, label %bb3
> +
> +bb40:                                             ; preds = %bb36
> +  store float %tmp38, float addrspace(1)* %arg, align 4
> +  ret void
> +}




More information about the llvm-commits mailing list