diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp --- a/llvm/lib/CodeGen/HardwareLoops.cpp +++ b/llvm/lib/CodeGen/HardwareLoops.cpp @@ -327,6 +327,11 @@ return false; } + assert( + Opts.Bitwidth.has_value() && Opts.Decrement.has_value() && + "Need to specify hardware-loop-counter-bitwidth and " + "hardware-loop-decrement=1 together when specify force-hardware-loops!"); + // Allow overriding of the counter width and loop decrement value. if (Opts.Bitwidth.has_value()) { HWLoopInfo.CountType = IntegerType::get(Ctx, Opts.Bitwidth.value()); diff --git a/llvm/test/Transforms/HardwareLoops/input-error.ll b/llvm/test/Transforms/HardwareLoops/input-error.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/HardwareLoops/input-error.ll @@ -0,0 +1,26 @@ +; RUN: not not opt -passes='hardware-loops' -S %s 2> %t.err +; RUN: FileCheck --check-prefix=CHECK < %t.err %s +; RUN: not not opt -passes='hardware-loops' -S %s 2> %t.err +; RUN: FileCheck --check-prefix=CHECK-NODECREMENT < %t.err %s +; RUN: not not opt -passes='hardware-loops' -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: "Need to specify hardware-loop-counter-bitwidth and " "hardware-loop-decrement=1 together!" +; CHECK-NODECREMENT: "Need to specify hardware-loop-counter-bitwidth and " "hardware-loop-decrement=1 together!" +; CHECK-NOBITWIDTH: "Need to specify hardware-loop-counter-bitwidth and " "hardware-loop-decrement=1 together!" +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 +}