From 77f046d7de7395b6e787bcd1a631075eaca23837 Mon Sep 17 00:00:00 2001 From: Steve Walk Date: Fri, 3 Jan 2025 08:09:13 -0800 Subject: [PATCH 1/2] hexagon-clang has segfault when -mllvm -debug and -O2 used --- .../Hexagon/HexagonLoopIdiomRecognition.cpp | 2 + llvm/test/CodeGen/Hexagon/loopIdiom.ll | 78 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 llvm/test/CodeGen/Hexagon/loopIdiom.ll diff --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp index 46a8ab395d32b..991ee5b1cbaa5 100644 --- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp +++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp @@ -1796,6 +1796,8 @@ bool PolynomialMultiplyRecognize::recognize() { IterCount = CV->getValue()->getZExtValue() + 1; Value *CIV = getCountIV(LoopB); + if (CIV == nullptr) + return false; ParsedValues PV; Simplifier PreSimp; PV.IterCount = IterCount; diff --git a/llvm/test/CodeGen/Hexagon/loopIdiom.ll b/llvm/test/CodeGen/Hexagon/loopIdiom.ll new file mode 100644 index 0000000000000..aa8532fd9ddbd --- /dev/null +++ b/llvm/test/CodeGen/Hexagon/loopIdiom.ll @@ -0,0 +1,78 @@ +; RUN: opt -debug -S -march=hexagon -O2 < %s | FileCheck %s +; REQUIRES: asserts +; CHECK: define dso_local void @complexMultAccum +; ModuleID = 'loopIdiom.c' +source_filename = "loopIdiom.c" +target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048" +target triple = "hexagon" + +; Function Attrs: noinline nounwind +define dso_local void @complexMultAccum(i32 noundef %n) #0 { +entry: + %n.addr = alloca i32, align 4 + %run_c_code = alloca i8, align 1 + %run_asm_code = alloca i8, align 1 + %iOutter = alloca i32, align 4 + %iOutter1 = alloca i32, align 4 + store i32 %n, ptr %n.addr, align 4 + store i8 1, ptr %run_c_code, align 1 + store i8 0, ptr %run_asm_code, align 1 + %0 = load i8, ptr %run_c_code, align 1 + %tobool = icmp ne i8 %0, 0 + br i1 %tobool, label %if.then, label %if.end + +if.then: ; preds = %entry + store i32 0, ptr %iOutter, align 4 + br label %for.cond + +for.cond: ; preds = %for.inc, %if.then + %1 = load i32, ptr %iOutter, align 4 + %cmp = icmp slt i32 %1, 2 + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %for.inc + +for.inc: ; preds = %for.body + %2 = load i32, ptr %iOutter, align 4 + %inc = add nsw i32 %2, 1 + store i32 %inc, ptr %iOutter, align 4 + br label %for.cond, !llvm.loop !3 + +for.end: ; preds = %for.cond + store i32 0, ptr %iOutter1, align 4 + br label %for.cond2 + +for.cond2: ; preds = %for.inc5, %for.end + %3 = load i32, ptr %iOutter1, align 4 + %cmp3 = icmp slt i32 %3, 2 + br i1 %cmp3, label %for.body4, label %for.end7 + +for.body4: ; preds = %for.cond2 + br label %for.inc5 + +for.inc5: ; preds = %for.body4 + %4 = load i32, ptr %iOutter1, align 4 + %inc6 = add nsw i32 %4, 1 + store i32 %inc6, ptr %iOutter1, align 4 + br label %for.cond2, !llvm.loop !5 + +for.end7: ; preds = %for.cond2 + br label %if.end + +if.end: ; preds = %for.end7, %entry + ret void +} + +attributes #0 = { noinline nounwind "approx-func-fp-math"="true" "frame-pointer"="all" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv79" "target-features"="+v79,-long-calls" "unsafe-fp-math"="true" } + +!llvm.module.flags = !{!0, !1} +!llvm.ident = !{!2} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 7, !"frame-pointer", i32 2} +!2 = !{!"QuIC LLVM Hexagon Clang version 19.0 Private Release: hexagon-clang-190"} +!3 = distinct !{!3, !4} +!4 = !{!"llvm.loop.mustprogress"} +!5 = distinct !{!5, !4} + From 419ebddcd2d296db62000076da4ca4d235566d05 Mon Sep 17 00:00:00 2001 From: Steve Walk Date: Tue, 7 Jan 2025 15:19:24 -0800 Subject: [PATCH 2/2] update per code review --- llvm/test/CodeGen/Hexagon/loopIdiom.ll | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/llvm/test/CodeGen/Hexagon/loopIdiom.ll b/llvm/test/CodeGen/Hexagon/loopIdiom.ll index aa8532fd9ddbd..9c3df674a4937 100644 --- a/llvm/test/CodeGen/Hexagon/loopIdiom.ll +++ b/llvm/test/CodeGen/Hexagon/loopIdiom.ll @@ -1,9 +1,6 @@ ; RUN: opt -debug -S -march=hexagon -O2 < %s | FileCheck %s ; REQUIRES: asserts ; CHECK: define dso_local void @complexMultAccum -; ModuleID = 'loopIdiom.c' -source_filename = "loopIdiom.c" -target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048" target triple = "hexagon" ; Function Attrs: noinline nounwind @@ -71,7 +68,7 @@ attributes #0 = { noinline nounwind "approx-func-fp-math"="true" "frame-pointer" !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 7, !"frame-pointer", i32 2} -!2 = !{!"QuIC LLVM Hexagon Clang version 19.0 Private Release: hexagon-clang-190"} +!2 = !{!"LLVM Clang"} !3 = distinct !{!3, !4} !4 = !{!"llvm.loop.mustprogress"} !5 = distinct !{!5, !4}