[ProfCheck] Add prof data for lowering of @llvm.cond.loop

When there is no target-specific lowering of @llvm.cond.loop, it is
lowered into a simple loop by PreISelIntrinsicLowering. Mark the branch
weights into the no-return loop as unknown given we do not have value
metadata to fix the profcheck test for this feature.

Reviewers: mtrofin, alanzhao1, snehasish, pcc

Pull Request: https://github.com/llvm/llvm-project/pull/180390
This commit is contained in:
Aiden Grossman 2026-02-08 10:16:58 -08:00 committed by GitHub
parent 33291dd944
commit 4d5d2ffd3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
@ -43,6 +44,8 @@
using namespace llvm;
#define DEBUG_TYPE "pre-isel-intrinsic-lowering"
/// Threshold to leave statically sized memory intrinsic calls. Calls of known
/// size larger than this will be expanded by the pass. Calls of unknown or
/// lower size will be left for expansion in codegen.
@ -619,7 +622,9 @@ static bool expandCondLoop(Function &Intr) {
auto *Call = cast<CallInst>(U);
auto *Br = cast<BranchInst>(
SplitBlockAndInsertIfThen(Call->getArgOperand(0), Call, false));
SplitBlockAndInsertIfThen(Call->getArgOperand(0), Call, false,
getExplicitlyUnknownBranchWeightsIfProfiled(
*Call->getFunction(), DEBUG_TYPE)));
Br->setSuccessor(0, Br->getParent());
Call->eraseFromParent();
}

View File

@ -3,17 +3,17 @@
; RUN: opt -mtriple=x86_64 -passes=pre-isel-intrinsic-lowering -S < %s | FileCheck --check-prefix=X86 %s
; RUN: opt -mtriple=mips64 -passes=pre-isel-intrinsic-lowering -S < %s | FileCheck --check-prefix=MIPS %s
define void @f1(i64 %a, i64 %b) {
define void @f1(i64 %a, i64 %b) !prof !0 {
; X86-LABEL: define void @f1(
; X86-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) {
; X86-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) !prof [[PROF0:![0-9]+]] {
; X86-NEXT: [[CMP:%.*]] = icmp ult i64 [[A]], [[B]]
; X86-NEXT: call void @llvm.cond.loop(i1 [[CMP]])
; X86-NEXT: ret void
;
; MIPS-LABEL: define void @f1(
; MIPS-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) {
; MIPS-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) !prof [[PROF0:![0-9]+]] {
; MIPS-NEXT: [[CMP:%.*]] = icmp ult i64 [[A]], [[B]]
; MIPS-NEXT: br i1 [[CMP]], label %[[BB1:.*]], label %[[BB2:.*]]
; MIPS-NEXT: br i1 [[CMP]], label %[[BB1:.*]], label %[[BB2:.*]], !prof [[PROF1:![0-9]+]]
; MIPS: [[BB1]]:
; MIPS-NEXT: br label %[[BB1]]
; MIPS: [[BB2]]:
@ -23,3 +23,11 @@ define void @f1(i64 %a, i64 %b) {
call void @llvm.cond.loop(i1 %cmp)
ret void
}
!0 = !{!"function_entry_count", i64 1000}
;.
; X86: [[PROF0]] = !{!"function_entry_count", i64 1000}
;.
; MIPS: [[PROF0]] = !{!"function_entry_count", i64 1000}
; MIPS: [[PROF1]] = !{!"unknown", !"pre-isel-intrinsic-lowering"}
;.

View File

@ -470,7 +470,6 @@ Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-gather.ll
Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-load.ll
Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-scatter.ll
Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-store.ll
Transforms/PreISelIntrinsicLowering/cond-loop.ll
Transforms/Scalarizer/basic-inseltpoison.ll
Transforms/Scalarizer/basic.ll
Transforms/Scalarizer/min-bits.ll