[llvm] [InstCombine] Preserve profile branch weights when folding logical booleans (PR #161293)
Alan Zhao via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 14:32:33 PDT 2025
https://github.com/alanzhao1 updated https://github.com/llvm/llvm-project/pull/161293
>From 64ebd5d0a90d72e5d0605e92ba52deca18ed5353 Mon Sep 17 00:00:00 2001
From: Alan Zhao <ayzhao at google.com>
Date: Mon, 29 Sep 2025 15:49:10 -0700
Subject: [PATCH 1/2] [InstCombine] Preserve profile branch weights when
folding logical booleans
Logical booleans in LLVM are represented by select statements - e.g. the
statement
```
A && B
```
is represented as
```
select i1 %A, i1 %B, i1 false
```
When LLVM folds two of the same logical booleans into a logical boolean
and a bitwise boolean (e.g. `A && B && C` -> `A && (B & C)`), the first
logical boolean is a select statement that retains the original
condition from the first logical boolean of the original statement. This
means that the new select statement has the branch weights as the
original select statement.
Tracking issue: #147390
---
llvm/include/llvm/IR/IRBuilder.h | 11 +-
.../InstCombine/InstCombineSelect.cpp | 11 +-
.../select-safe-bool-transforms.ll | 302 +++++++++---------
3 files changed, 172 insertions(+), 152 deletions(-)
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 783f8f6d2478c..041a4ce112275 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1722,16 +1722,19 @@ class IRBuilderBase {
return Insert(BinOp, Name);
}
- Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "") {
+ Value *CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name = "",
+ Instruction *MDFrom = nullptr) {
assert(Cond2->getType()->isIntOrIntVectorTy(1));
return CreateSelect(Cond1, Cond2,
- ConstantInt::getNullValue(Cond2->getType()), Name);
+ ConstantInt::getNullValue(Cond2->getType()), Name,
+ MDFrom);
}
- Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "") {
+ Value *CreateLogicalOr(Value *Cond1, Value *Cond2, const Twine &Name = "",
+ Instruction *MDFrom = nullptr) {
assert(Cond2->getType()->isIntOrIntVectorTy(1));
return CreateSelect(Cond1, ConstantInt::getAllOnesValue(Cond2->getType()),
- Cond2, Name);
+ Cond2, Name, MDFrom);
}
Value *CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2,
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index b6b3a95f35c76..459c7e02254fe 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -50,6 +50,7 @@
using namespace llvm;
using namespace PatternMatch;
+extern cl::opt<bool> ProfcheckDisableMetadataFixes;
/// Replace a select operand based on an equality comparison with the identity
/// constant of a binop.
@@ -3369,7 +3370,10 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
impliesPoisonOrCond(FalseVal, B, /*Expected=*/false)) {
// (A || B) || C --> A || (B | C)
return replaceInstUsesWith(
- SI, Builder.CreateLogicalOr(A, Builder.CreateOr(B, FalseVal)));
+ SI, Builder.CreateLogicalOr(A, Builder.CreateOr(B, FalseVal), "",
+ ProfcheckDisableMetadataFixes
+ ? nullptr
+ : cast<SelectInst>(CondVal)));
}
// (A && B) || (C && B) --> (A || C) && B
@@ -3411,7 +3415,10 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
impliesPoisonOrCond(TrueVal, B, /*Expected=*/true)) {
// (A && B) && C --> A && (B & C)
return replaceInstUsesWith(
- SI, Builder.CreateLogicalAnd(A, Builder.CreateAnd(B, TrueVal)));
+ SI, Builder.CreateLogicalAnd(A, Builder.CreateAnd(B, TrueVal), "",
+ ProfcheckDisableMetadataFixes
+ ? nullptr
+ : cast<SelectInst>(CondVal)));
}
// (A || B) && (C || B) --> (A && C) || B
diff --git a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
index 9de9150f62ed4..4ac61f65862b1 100644
--- a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
+++ b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
; TODO: All of these should be optimized to less than or equal to a single
@@ -7,502 +7,512 @@
; --- (A op B) op' A / (B op A) op' A ---
; (A land B) land A
-define i1 @land_land_left1(i1 %A, i1 %B) {
+define i1 @land_land_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_land_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 %B, i1 false
- %res = select i1 %c, i1 %A, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
-define i1 @land_land_left2(i1 %A, i1 %B) {
+define i1 @land_land_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_land_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2:![0-9]+]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 %A, i1 false
- %res = select i1 %c, i1 %A, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
; (A land B) band A
-define i1 @land_band_left1(i1 %A, i1 %B) {
+define i1 @land_band_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_band_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 %B, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
%res = and i1 %c, %A
ret i1 %res
}
-define i1 @land_band_left2(i1 %A, i1 %B) {
+define i1 @land_band_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_band_left2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 %A, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
%res = and i1 %c, %A
ret i1 %res
}
; (A land B) lor A
-define i1 @land_lor_left1(i1 %A, i1 %B) {
+define i1 @land_lor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_lor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false
- %res = select i1 %c, i1 true, i1 %A
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
-define i1 @land_lor_left2(i1 %A, i1 %B) {
+define i1 @land_lor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_lor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false
- %res = select i1 %c, i1 true, i1 %A
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
; (A land B) bor A
-define i1 @land_bor_left1(i1 %A, i1 %B) {
+define i1 @land_bor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_bor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
%res = or i1 %c, %A
ret i1 %res
}
-define i1 @land_bor_left2(i1 %A, i1 %B) {
+define i1 @land_bor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_bor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
%res = or i1 %c, %A
ret i1 %res
}
; (A band B) land A
-define i1 @band_land_left1(i1 %A, i1 %B) {
+define i1 @band_land_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_land_left1(
; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = and i1 %A, %B
- %res = select i1 %c, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
-define i1 @band_land_left2(i1 %A, i1 %B) {
+define i1 @band_land_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_land_left2(
; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = and i1 %B, %A
- %res = select i1 %c, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
; (A band B) lor A
-define i1 @band_lor_left1(i1 %A, i1 %B) {
+define i1 @band_lor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_lor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %A, %B
- %res = select i1 %c, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
-define i1 @band_lor_left2(i1 %A, i1 %B) {
+define i1 @band_lor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_lor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %B, %A
- %res = select i1 %c, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
; (A lor B) land A
-define i1 @lor_land_left1(i1 %A, i1 %B) {
+define i1 @lor_land_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_land_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B
- %res = select i1 %c, i1 %A, i1 false
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
-define i1 @lor_land_left2(i1 %A, i1 %B) {
+define i1 @lor_land_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_land_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A
- %res = select i1 %c, i1 %A, i1 false
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
; (A lor B) band A
-define i1 @lor_band_left1(i1 %A, i1 %B) {
+define i1 @lor_band_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_band_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
%res = and i1 %c, %A
ret i1 %res
}
-define i1 @lor_band_left2(i1 %A, i1 %B) {
+define i1 @lor_band_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_band_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
%res = and i1 %c, %A
ret i1 %res
}
; (A lor B) lor A
-define i1 @lor_lor_left1(i1 %A, i1 %B) {
+define i1 @lor_lor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_lor_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 true, i1 %B
- %res = select i1 %c, i1 true, i1 %A
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
-define i1 @lor_lor_left2(i1 %A, i1 %B) {
+define i1 @lor_lor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_lor_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 true, i1 %A
- %res = select i1 %c, i1 true, i1 %A
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
; (A lor B) bor A
-define i1 @lor_bor_left1(i1 %A, i1 %B) {
+define i1 @lor_bor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_bor_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 true, i1 %B
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
%res = or i1 %c, %A
ret i1 %res
}
-define i1 @lor_bor_left2(i1 %A, i1 %B) {
+define i1 @lor_bor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_bor_left2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 true, i1 %A
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
%res = or i1 %c, %A
ret i1 %res
}
; (A bor B) land A
-define i1 @bor_land_left1(i1 %A, i1 %B) {
+define i1 @bor_land_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_land_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %A, %B
- %res = select i1 %c, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
-define i1 @bor_land_left2(i1 %A, i1 %B) {
+define i1 @bor_land_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_land_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %B, %A
- %res = select i1 %c, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
; (A bor B) lor A
-define i1 @bor_lor_left1(i1 %A, i1 %B) {
+define i1 @bor_lor_left1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_lor_left1(
; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = or i1 %A, %B
- %res = select i1 %c, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
-define i1 @bor_lor_left2(i1 %A, i1 %B) {
+define i1 @bor_lor_left2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_lor_left2(
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = or i1 %B, %A
- %res = select i1 %c, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
; --- A op (A op' B) / A op (B op' A) ---
; A land (A land B)
-define i1 @land_land_right1(i1 %A, i1 %B) {
+define i1 @land_land_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_land_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %A, i1 %B, i1 false
- %res = select i1 %A, i1 %c, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
-define i1 @land_land_right2(i1 %A, i1 %B) {
+define i1 @land_land_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 %A, i1 false
- %res = select i1 %A, i1 %c, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
; A band (A land B)
-define i1 @land_band_right1(i1 %A, i1 %B) {
+define i1 @land_band_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_band_right1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 %B, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
%res = and i1 %A, %c
ret i1 %res
}
-define i1 @land_band_right2(i1 %A, i1 %B) {
+define i1 @land_band_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_band_right2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 %A, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
%res = and i1 %A, %c
ret i1 %res
}
; A lor (A land B)
-define i1 @land_lor_right1(i1 %A, i1 %B) {
+define i1 @land_lor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_lor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false
- %res = select i1 %A, i1 true, i1 %c
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
-define i1 @land_lor_right2(i1 %A, i1 %B) {
+define i1 @land_lor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_lor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false
- %res = select i1 %A, i1 true, i1 %c
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
-define <2 x i1> @land_lor_right1_vec(<2 x i1> %A, <2 x i1> %B) {
+define <2 x i1> @land_lor_right1_vec(<2 x i1> %A, <2 x i1> %B) !prof !0 {
; CHECK-LABEL: @land_lor_right1_vec(
; CHECK-NEXT: ret <2 x i1> [[A:%.*]]
;
- %c = select <2 x i1> %A, <2 x i1> %B, <2 x i1> zeroinitializer
- %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c
+ %c = select <2 x i1> %A, <2 x i1> %B, <2 x i1> zeroinitializer, !prof !1
+ %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c, !prof !1
ret <2 x i1> %res
}
-define <2 x i1> @land_lor_right2_vec(<2 x i1> %A, <2 x i1> %B) {
+define <2 x i1> @land_lor_right2_vec(<2 x i1> %A, <2 x i1> %B) !prof !0 {
; CHECK-LABEL: @land_lor_right2_vec(
; CHECK-NEXT: ret <2 x i1> [[A:%.*]]
;
- %c = select <2 x i1> %B, <2 x i1> %A, <2 x i1> zeroinitializer
- %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c
+ %c = select <2 x i1> %B, <2 x i1> %A, <2 x i1> zeroinitializer, !prof !3
+ %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c, !prof !1
ret <2 x i1> %res
}
; A bor (A land B)
-define i1 @land_bor_right1(i1 %A, i1 %B) {
+define i1 @land_bor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_bor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false
+ %c = select i1 %A, i1 %B, i1 false, !prof !1
%res = or i1 %A, %c
ret i1 %res
}
-define i1 @land_bor_right2(i1 %A, i1 %B) {
+define i1 @land_bor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @land_bor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false
+ %c = select i1 %B, i1 %A, i1 false, !prof !3
%res = or i1 %A, %c
ret i1 %res
}
; A land (A band B)
-define i1 @band_land_right1(i1 %A, i1 %B) {
+define i1 @band_land_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_land_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %A, %B
- %res = select i1 %A, i1 %c, i1 false
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
-define i1 @band_land_right2(i1 %A, i1 %B) {
+define i1 @band_land_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %B, %A
- %res = select i1 %A, i1 %c, i1 false
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
; A lor (A band B)
-define i1 @band_lor_right1(i1 %A, i1 %B) {
+define i1 @band_lor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_lor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %A, %B
- %res = select i1 %A, i1 true, i1 %c
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
-define i1 @band_lor_right2(i1 %A, i1 %B) {
+define i1 @band_lor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @band_lor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %B, %A
- %res = select i1 %A, i1 true, i1 %c
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
; A land (A lor B)
-define i1 @lor_land_right1(i1 %A, i1 %B) {
+define i1 @lor_land_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_land_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B
- %res = select i1 %A, i1 %c, i1 false
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
-define i1 @lor_land_right2(i1 %A, i1 %B) {
+define i1 @lor_land_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_land_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A
- %res = select i1 %A, i1 %c, i1 false
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
; A band (A lor B)
-define i1 @lor_band_right1(i1 %A, i1 %B) {
+define i1 @lor_band_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_band_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
%res = and i1 %A, %c
ret i1 %res
}
-define i1 @lor_band_right2(i1 %A, i1 %B) {
+define i1 @lor_band_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_band_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
%res = and i1 %A, %c
ret i1 %res
}
; A lor (A lor B)
-define i1 @lor_lor_right1(i1 %A, i1 %B) {
+define i1 @lor_lor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_lor_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %A, i1 true, i1 %B
- %res = select i1 %A, i1 true, i1 %c
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
-define i1 @lor_lor_right2(i1 %A, i1 %B) {
+define i1 @lor_lor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 true, i1 %A
- %res = select i1 %A, i1 true, i1 %c
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
; A bor (A lor B)
-define i1 @lor_bor_right1(i1 %A, i1 %B) {
+define i1 @lor_bor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_bor_right1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 true, i1 %B
+ %c = select i1 %A, i1 true, i1 %B, !prof !1
%res = or i1 %A, %c
ret i1 %res
}
-define i1 @lor_bor_right2(i1 %A, i1 %B) {
+define i1 @lor_bor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @lor_bor_right2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 true, i1 %A
+ %c = select i1 %B, i1 true, i1 %A, !prof !3
%res = or i1 %A, %c
ret i1 %res
}
; A land (A bor B)
-define i1 @bor_land_right1(i1 %A, i1 %B) {
+define i1 @bor_land_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_land_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %A, %B
- %res = select i1 %A, i1 %c, i1 false
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
-define i1 @bor_land_right2(i1 %A, i1 %B) {
+define i1 @bor_land_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_land_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %B, %A
- %res = select i1 %A, i1 %c, i1 false
+ %res = select i1 %A, i1 %c, i1 false, !prof !1
ret i1 %res
}
; A lor (A bor B)
-define i1 @bor_lor_right1(i1 %A, i1 %B) {
+define i1 @bor_lor_right1(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_lor_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %A, %B
- %res = select i1 %A, i1 true, i1 %c
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
-define i1 @bor_lor_right2(i1 %A, i1 %B) {
+define i1 @bor_lor_right2(i1 %A, i1 %B) !prof !0 {
; CHECK-LABEL: @bor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %B, %A
- %res = select i1 %A, i1 true, i1 %c
+ %res = select i1 %A, i1 true, i1 %c, !prof !1
ret i1 %res
}
; Value equivalence substitution does not account for vector
; transforms, so it needs a scalar condition operand.
-; For example, this would miscompile if %a = {1, 0}.
+; For example, this would miscompile if %a = !prof !0 {1, 0}.
-define <2 x i1> @PR50500_trueval(<2 x i1> %a, <2 x i1> %b) {
+define <2 x i1> @PR50500_trueval(<2 x i1> %a, <2 x i1> %b) !prof !0 {
; CHECK-LABEL: @PR50500_trueval(
; CHECK-NEXT: [[S:%.*]] = shufflevector <2 x i1> [[A:%.*]], <2 x i1> poison, <2 x i32> <i32 1, i32 0>
-; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[S]], <2 x i1> [[B:%.*]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[S]], <2 x i1> [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: ret <2 x i1> [[R]]
;
%s = shufflevector <2 x i1> %a, <2 x i1> poison, <2 x i32> <i32 1, i32 0>
- %r = select <2 x i1> %a, <2 x i1> %s, <2 x i1> %b
+ %r = select <2 x i1> %a, <2 x i1> %s, <2 x i1> %b, !prof !1
ret <2 x i1> %r
}
-define <2 x i1> @PR50500_falseval(<2 x i1> %a, <2 x i1> %b) {
+define <2 x i1> @PR50500_falseval(<2 x i1> %a, <2 x i1> %b) !prof !0 {
; CHECK-LABEL: @PR50500_falseval(
; CHECK-NEXT: [[S:%.*]] = shufflevector <2 x i1> [[A:%.*]], <2 x i1> poison, <2 x i32> <i32 1, i32 0>
-; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[B:%.*]], <2 x i1> [[S]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[B:%.*]], <2 x i1> [[S]], !prof [[PROF1]]
; CHECK-NEXT: ret <2 x i1> [[R]]
;
%s = shufflevector <2 x i1> %a, <2 x i1> poison, <2 x i32> <i32 1, i32 0>
- %r = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %s
+ %r = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %s, !prof !1
ret <2 x i1> %r
}
+
+!0 = !{!"function_entry_count", i64 1000}
+!1 = !{!"branch_weights", i32 2, i32 3}
+!2 = !{!"branch_weights", i32 5, i32 7}
+!3 = !{!"branch_weights", i32 11, i32 13}
+;.
+; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 11, i32 13}
+;.
>From 3456186367fc9ca01f0965d37ec2f386129609ed Mon Sep 17 00:00:00 2001
From: Alan Zhao <ayzhao at google.com>
Date: Tue, 30 Sep 2025 14:27:41 -0700
Subject: [PATCH 2/2] make tests targeted
---
.../select-safe-bool-transforms.ll | 277 +++++++++---------
1 file changed, 138 insertions(+), 139 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
index 4ac61f65862b1..8b0a5ca62918c 100644
--- a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
+++ b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
@@ -16,142 +16,142 @@ define i1 @land_land_left1(i1 %A, i1 %B) !prof !0 {
%res = select i1 %c, i1 %A, i1 false, !prof !2
ret i1 %res
}
-define i1 @land_land_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_land_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_land_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2:![0-9]+]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
; (A land B) band A
-define i1 @land_band_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_band_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_band_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
%res = and i1 %c, %A
ret i1 %res
}
-define i1 @land_band_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_band_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_band_left2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %c = select i1 %B, i1 %A, i1 false
%res = and i1 %c, %A
ret i1 %res
}
; (A land B) lor A
-define i1 @land_lor_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_lor_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_lor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @land_lor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_lor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_lor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
; (A land B) bor A
-define i1 @land_bor_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_bor_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_bor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
%res = or i1 %c, %A
ret i1 %res
}
-define i1 @land_bor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_bor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_bor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %c = select i1 %B, i1 %A, i1 false
%res = or i1 %c, %A
ret i1 %res
}
; (A band B) land A
-define i1 @band_land_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @band_land_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_left1(
; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = and i1 %A, %B
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-define i1 @band_land_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @band_land_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_left2(
; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = and i1 %B, %A
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
; (A band B) lor A
-define i1 @band_lor_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @band_lor_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %A, %B
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @band_lor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @band_lor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %B, %A
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
; (A lor B) land A
-define i1 @lor_land_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_land_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_land_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-define i1 @lor_land_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_land_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_land_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
; (A lor B) band A
-define i1 @lor_band_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_band_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_band_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
%res = and i1 %c, %A
ret i1 %res
}
-define i1 @lor_band_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_band_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_band_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %c = select i1 %B, i1 true, i1 %A
%res = and i1 %c, %A
ret i1 %res
}
@@ -166,353 +166,352 @@ define i1 @lor_lor_left1(i1 %A, i1 %B) !prof !0 {
%res = select i1 %c, i1 true, i1 %A, !prof !2
ret i1 %res
}
-define i1 @lor_lor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_lor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_lor_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
; (A lor B) bor A
-define i1 @lor_bor_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_bor_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_bor_left1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
%res = or i1 %c, %A
ret i1 %res
}
-define i1 @lor_bor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_bor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_bor_left2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %c = select i1 %B, i1 true, i1 %A
%res = or i1 %c, %A
ret i1 %res
}
; (A bor B) land A
-define i1 @bor_land_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_land_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_left1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %A, %B
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
-define i1 @bor_land_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_land_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_left2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %B, %A
- %res = select i1 %c, i1 %A, i1 false, !prof !2
+ %res = select i1 %c, i1 %A, i1 false
ret i1 %res
}
; (A bor B) lor A
-define i1 @bor_lor_left1(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_lor_left1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_left1(
; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = or i1 %A, %B
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
-define i1 @bor_lor_left2(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_lor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_left2(
; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%c = or i1 %B, %A
- %res = select i1 %c, i1 true, i1 %A, !prof !2
+ %res = select i1 %c, i1 true, i1 %A
ret i1 %res
}
; --- A op (A op' B) / A op (B op' A) ---
; A land (A land B)
-define i1 @land_land_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_land_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-define i1 @land_land_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
; A band (A land B)
-define i1 @land_band_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_band_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_band_right1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
%res = and i1 %A, %c
ret i1 %res
}
-define i1 @land_band_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_band_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_band_right2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false, !prof [[PROF2]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %c = select i1 %B, i1 %A, i1 false
%res = and i1 %A, %c
ret i1 %res
}
; A lor (A land B)
-define i1 @land_lor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_lor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define i1 @land_lor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_lor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %c = select i1 %B, i1 %A, i1 false
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define <2 x i1> @land_lor_right1_vec(<2 x i1> %A, <2 x i1> %B) !prof !0 {
+define <2 x i1> @land_lor_right1_vec(<2 x i1> %A, <2 x i1> %B) {
; CHECK-LABEL: @land_lor_right1_vec(
; CHECK-NEXT: ret <2 x i1> [[A:%.*]]
;
- %c = select <2 x i1> %A, <2 x i1> %B, <2 x i1> zeroinitializer, !prof !1
- %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c, !prof !1
+ %c = select <2 x i1> %A, <2 x i1> %B, <2 x i1> zeroinitializer
+ %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c
ret <2 x i1> %res
}
-define <2 x i1> @land_lor_right2_vec(<2 x i1> %A, <2 x i1> %B) !prof !0 {
+define <2 x i1> @land_lor_right2_vec(<2 x i1> %A, <2 x i1> %B) {
; CHECK-LABEL: @land_lor_right2_vec(
; CHECK-NEXT: ret <2 x i1> [[A:%.*]]
;
- %c = select <2 x i1> %B, <2 x i1> %A, <2 x i1> zeroinitializer, !prof !3
- %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c, !prof !1
+ %c = select <2 x i1> %B, <2 x i1> %A, <2 x i1> zeroinitializer
+ %res = select <2 x i1> %A, <2 x i1> <i1 true, i1 true>, <2 x i1> %c
ret <2 x i1> %res
}
; A bor (A land B)
-define i1 @land_bor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @land_bor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @land_bor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 %B, i1 false, !prof !1
+ %c = select i1 %A, i1 %B, i1 false
%res = or i1 %A, %c
ret i1 %res
}
-define i1 @land_bor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @land_bor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_bor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 %A, i1 false, !prof !3
+ %c = select i1 %B, i1 %A, i1 false
%res = or i1 %A, %c
ret i1 %res
}
; A land (A band B)
-define i1 @band_land_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @band_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %A, %B
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-define i1 @band_land_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @band_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false, !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %B, %A
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
; A lor (A band B)
-define i1 @band_lor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @band_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %A, %B
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define i1 @band_lor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @band_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = and i1 %B, %A
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
; A land (A lor B)
-define i1 @lor_land_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_land_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-define i1 @lor_land_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_land_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
; A band (A lor B)
-define i1 @lor_band_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_band_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_band_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
%res = and i1 %A, %c
ret i1 %res
}
-define i1 @lor_band_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_band_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_band_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %c = select i1 %B, i1 true, i1 %A
%res = and i1 %A, %c
ret i1 %res
}
; A lor (A lor B)
-define i1 @lor_lor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_lor_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define i1 @lor_lor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[RES]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %c = select i1 %B, i1 true, i1 %A
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
; A bor (A lor B)
-define i1 @lor_bor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_bor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_bor_right1(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %A, i1 true, i1 %B, !prof !1
+ %c = select i1 %A, i1 true, i1 %B
%res = or i1 %A, %c
ret i1 %res
}
-define i1 @lor_bor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @lor_bor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_bor_right2(
-; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]], !prof [[PROF2]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
- %c = select i1 %B, i1 true, i1 %A, !prof !3
+ %c = select i1 %B, i1 true, i1 %A
%res = or i1 %A, %c
ret i1 %res
}
; A land (A bor B)
-define i1 @bor_land_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_right1(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %A, %B
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
-define i1 @bor_land_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_right2(
; CHECK-NEXT: ret i1 [[A:%.*]]
;
%c = or i1 %B, %A
- %res = select i1 %A, i1 %c, i1 false, !prof !1
+ %res = select i1 %A, i1 %c, i1 false
ret i1 %res
}
; A lor (A bor B)
-define i1 @bor_lor_right1(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %A, %B
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
-define i1 @bor_lor_right2(i1 %A, i1 %B) !prof !0 {
+define i1 @bor_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %B, %A
- %res = select i1 %A, i1 true, i1 %c, !prof !1
+ %res = select i1 %A, i1 true, i1 %c
ret i1 %res
}
; Value equivalence substitution does not account for vector
; transforms, so it needs a scalar condition operand.
-; For example, this would miscompile if %a = !prof !0 {1, 0}.
+; For example, this would miscompile if %a = {1, 0}.
-define <2 x i1> @PR50500_trueval(<2 x i1> %a, <2 x i1> %b) !prof !0 {
+define <2 x i1> @PR50500_trueval(<2 x i1> %a, <2 x i1> %b) {
; CHECK-LABEL: @PR50500_trueval(
; CHECK-NEXT: [[S:%.*]] = shufflevector <2 x i1> [[A:%.*]], <2 x i1> poison, <2 x i32> <i32 1, i32 0>
-; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[S]], <2 x i1> [[B:%.*]], !prof [[PROF1]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[S]], <2 x i1> [[B:%.*]]
; CHECK-NEXT: ret <2 x i1> [[R]]
;
%s = shufflevector <2 x i1> %a, <2 x i1> poison, <2 x i32> <i32 1, i32 0>
- %r = select <2 x i1> %a, <2 x i1> %s, <2 x i1> %b, !prof !1
+ %r = select <2 x i1> %a, <2 x i1> %s, <2 x i1> %b
ret <2 x i1> %r
}
-define <2 x i1> @PR50500_falseval(<2 x i1> %a, <2 x i1> %b) !prof !0 {
+define <2 x i1> @PR50500_falseval(<2 x i1> %a, <2 x i1> %b) {
; CHECK-LABEL: @PR50500_falseval(
; CHECK-NEXT: [[S:%.*]] = shufflevector <2 x i1> [[A:%.*]], <2 x i1> poison, <2 x i32> <i32 1, i32 0>
-; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[B:%.*]], <2 x i1> [[S]], !prof [[PROF1]]
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[A]], <2 x i1> [[B:%.*]], <2 x i1> [[S]]
; CHECK-NEXT: ret <2 x i1> [[R]]
;
%s = shufflevector <2 x i1> %a, <2 x i1> poison, <2 x i32> <i32 1, i32 0>
- %r = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %s, !prof !1
+ %r = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %s
ret <2 x i1> %r
}
!0 = !{!"function_entry_count", i64 1000}
!1 = !{!"branch_weights", i32 2, i32 3}
!2 = !{!"branch_weights", i32 5, i32 7}
-!3 = !{!"branch_weights", i32 11, i32 13}
+
;.
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
-; CHECK: [[PROF2]] = !{!"branch_weights", i32 11, i32 13}
;.
More information about the llvm-commits
mailing list