[PATCH] D146277: add assert to confirm input is valid for pass HardwareLoops

Wang, Xin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 23:58:35 PDT 2023


XinWang10 updated this revision to Diff 507625.
XinWang10 added a comment.

try rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146277/new/

https://reviews.llvm.org/D146277

Files:
  llvm/lib/CodeGen/HardwareLoops.cpp
  llvm/test/Transforms/HardwareLoops/input-error.ll


Index: llvm/test/Transforms/HardwareLoops/input-error.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/HardwareLoops/input-error.ll
@@ -0,0 +1,26 @@
+; RUN: not --crash opt -passes='hardware-loops<force-hardware-loops>' -S %s 2> %t.err
+; RUN: FileCheck --check-prefix=CHECK < %t.err %s
+; RUN: not --crash opt -passes='hardware-loops<force-hardware-loops;hardware-loop-counter-bitwidth=32>' -S %s 2> %t.err
+; RUN: FileCheck --check-prefix=CHECK-NODECREMENT < %t.err %s
+; RUN: not --crash opt -passes='hardware-loops<force-hardware-loops;hardware-loop-decrement=1>' -S %s 2> %t.err
+; RUN: FileCheck --check-prefix=CHECK-NOBITWIDTH < %t.err %s
+
+define void @while_lt(i32 %i, i32 %N, ptr nocapture %A) {
+; CHECK: HWLoopInfo.CountType could not be nullptr!
+; CHECK-NODECREMENT: LoopDecrement can not be nullptr!
+; CHECK-NOBITWIDTH: HWLoopInfo.CountType could not be nullptr!
+entry:
+  %cmp4 = icmp ult i32 %i, %N
+  br i1 %cmp4, label %while.body, label %while.end
+
+while.body:
+  %i.addr.05 = phi i32 [ %inc, %while.body ], [ %i, %entry ]
+  %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.addr.05
+  store i32 %i.addr.05, ptr %arrayidx, align 4
+  %inc = add nuw i32 %i.addr.05, 1
+  %exitcond = icmp eq i32 %inc, %N
+  br i1 %exitcond, label %while.end, label %while.body
+
+while.end:
+  ret void
+}
Index: llvm/lib/CodeGen/HardwareLoops.cpp
===================================================================
--- llvm/lib/CodeGen/HardwareLoops.cpp
+++ llvm/lib/CodeGen/HardwareLoops.cpp
@@ -332,9 +332,12 @@
     HWLoopInfo.CountType = IntegerType::get(Ctx, Opts.Bitwidth.value());
   }
 
-  if (Opts.Decrement.has_value())
+  if (Opts.Decrement.has_value()) {
+    assert(HWLoopInfo.CountType &&
+           "HWLoopInfo.CountType could not be nullptr!");
     HWLoopInfo.LoopDecrement =
-      ConstantInt::get(HWLoopInfo.CountType, Opts.Decrement.value());
+        ConstantInt::get(HWLoopInfo.CountType, Opts.Decrement.value());
+  }
 
   MadeChange |= TryConvertLoop(HWLoopInfo);
   return MadeChange && (!HWLoopInfo.IsNestingLegal && !Opts.ForceNested);
@@ -342,9 +345,9 @@
 
 bool HardwareLoopsImpl::TryConvertLoop(HardwareLoopInfo &HWLoopInfo) {
 
+  assert(HWLoopInfo.CountType && "HWLoopInfo.CountType could not be nullptr!");
   Loop *L = HWLoopInfo.L;
   LLVM_DEBUG(dbgs() << "HWLoops: Try to convert profitable loop: " << *L);
-
   if (!HWLoopInfo.isHardwareLoopCandidate(SE, LI, DT, Opts.getForceNested(),
                                           Opts.getForcePhi())) {
     // TODO: there can be many reasons a loop is not considered a
@@ -534,6 +537,7 @@
 }
 
 void HardwareLoop::InsertLoopDec() {
+  assert(LoopDecrement && "LoopDecrement can not be nullptr!");
   IRBuilder<> CondBuilder(ExitBranch);
 
   Function *DecFunc =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146277.507625.patch
Type: text/x-patch
Size: 2826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230323/348b0459/attachment.bin>


More information about the llvm-commits mailing list