2017-10-11 23:56:44 +02:00
|
|
|
//===-- PredicateInfo.cpp - PredicateInfo Builder--------------------===//
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
//
|
2017-10-11 23:56:44 +02:00
|
|
|
//===----------------------------------------------------------------===//
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
//
|
|
|
|
// This file implements the PredicateInfo class.
|
|
|
|
//
|
2017-10-11 23:56:44 +02:00
|
|
|
//===----------------------------------------------------------------===//
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
|
|
|
#include "llvm/Transforms/Utils/PredicateInfo.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2017-10-11 23:56:44 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2018-07-24 16:49:52 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
2017-10-11 23:56:44 +02:00
|
|
|
#include "llvm/Analysis/CFG.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/IR/AssemblyAnnotationWriter.h"
|
2017-10-11 23:56:44 +02:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2017-10-11 23:56:44 +02:00
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2018-07-24 16:49:52 +02:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2017-10-11 23:56:44 +02:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Metadata.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/IR/PatternMatch.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2017-02-19 05:29:01 +01:00
|
|
|
#include "llvm/Support/DebugCounter.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2018-03-28 19:44:36 +02:00
|
|
|
#include "llvm/Transforms/Utils.h"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
#include <algorithm>
|
2017-10-11 23:56:44 +02:00
|
|
|
#define DEBUG_TYPE "predicateinfo"
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace PatternMatch;
|
|
|
|
using namespace llvm::PredicateInfoClasses;
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(PredicateInfoPrinterLegacyPass, "print-predicateinfo",
|
|
|
|
"PredicateInfo Printer", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
|
|
|
INITIALIZE_PASS_END(PredicateInfoPrinterLegacyPass, "print-predicateinfo",
|
|
|
|
"PredicateInfo Printer", false, false)
|
|
|
|
static cl::opt<bool> VerifyPredicateInfo(
|
|
|
|
"verify-predicateinfo", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Verify PredicateInfo in legacy printer pass."));
|
2017-02-19 05:29:01 +01:00
|
|
|
DEBUG_COUNTER(RenameCounter, "predicateinfo-rename",
|
2017-08-10 19:48:11 +02:00
|
|
|
"Controls which variables are renamed with predicateinfo");
|
|
|
|
|
2017-10-11 23:56:44 +02:00
|
|
|
namespace {
|
2017-02-22 23:20:58 +01:00
|
|
|
// Given a predicate info that is a type of branching terminator, get the
|
|
|
|
// branching block.
|
2017-10-11 23:56:44 +02:00
|
|
|
const BasicBlock *getBranchBlock(const PredicateBase *PB) {
|
2017-02-22 23:20:58 +01:00
|
|
|
assert(isa<PredicateWithEdge>(PB) &&
|
|
|
|
"Only branches and switches should have PHIOnly defs that "
|
|
|
|
"require branch blocks.");
|
|
|
|
return cast<PredicateWithEdge>(PB)->From;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a predicate info that is a type of branching terminator, get the
|
|
|
|
// branching terminator.
|
|
|
|
static Instruction *getBranchTerminator(const PredicateBase *PB) {
|
|
|
|
assert(isa<PredicateWithEdge>(PB) &&
|
|
|
|
"Not a predicate info type we know how to get a terminator from.");
|
|
|
|
return cast<PredicateWithEdge>(PB)->From->getTerminator();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given a predicate info that is a type of branching terminator, get the
|
|
|
|
// edge this predicate info represents
|
2017-10-11 23:56:44 +02:00
|
|
|
const std::pair<BasicBlock *, BasicBlock *>
|
2017-02-22 23:20:58 +01:00
|
|
|
getBlockEdge(const PredicateBase *PB) {
|
|
|
|
assert(isa<PredicateWithEdge>(PB) &&
|
|
|
|
"Not a predicate info type we know how to get an edge from.");
|
|
|
|
const auto *PEdge = cast<PredicateWithEdge>(PB);
|
|
|
|
return std::make_pair(PEdge->From, PEdge->To);
|
|
|
|
}
|
|
|
|
}
|
2017-02-19 05:29:01 +01:00
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
namespace llvm {
|
|
|
|
namespace PredicateInfoClasses {
|
|
|
|
enum LocalNum {
|
|
|
|
// Operations that must appear first in the block.
|
|
|
|
LN_First,
|
|
|
|
// Operations that are somewhere in the middle of the block, and are sorted on
|
|
|
|
// demand.
|
|
|
|
LN_Middle,
|
|
|
|
// Operations that must appear last in a block, like successor phi node uses.
|
|
|
|
LN_Last
|
|
|
|
};
|
|
|
|
|
|
|
|
// Associate global and local DFS info with defs and uses, so we can sort them
|
|
|
|
// into a global domination ordering.
|
|
|
|
struct ValueDFS {
|
|
|
|
int DFSIn = 0;
|
|
|
|
int DFSOut = 0;
|
|
|
|
unsigned int LocalNum = LN_Middle;
|
|
|
|
// Only one of Def or Use will be set.
|
|
|
|
Value *Def = nullptr;
|
2017-02-07 23:11:43 +01:00
|
|
|
Use *U = nullptr;
|
2017-02-19 00:06:38 +01:00
|
|
|
// Neither PInfo nor EdgeOnly participate in the ordering
|
2017-02-12 23:12:20 +01:00
|
|
|
PredicateBase *PInfo = nullptr;
|
2017-02-19 00:06:38 +01:00
|
|
|
bool EdgeOnly = false;
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
};
|
|
|
|
|
2017-10-11 23:56:44 +02:00
|
|
|
// Perform a strict weak ordering on instructions and arguments.
|
|
|
|
static bool valueComesBefore(OrderedInstructions &OI, const Value *A,
|
|
|
|
const Value *B) {
|
|
|
|
auto *ArgA = dyn_cast_or_null<Argument>(A);
|
|
|
|
auto *ArgB = dyn_cast_or_null<Argument>(B);
|
|
|
|
if (ArgA && !ArgB)
|
|
|
|
return true;
|
|
|
|
if (ArgB && !ArgA)
|
|
|
|
return false;
|
|
|
|
if (ArgA && ArgB)
|
|
|
|
return ArgA->getArgNo() < ArgB->getArgNo();
|
2018-06-20 19:42:01 +02:00
|
|
|
return OI.dfsBefore(cast<Instruction>(A), cast<Instruction>(B));
|
2017-10-11 23:56:44 +02:00
|
|
|
}
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
// This compares ValueDFS structures, creating OrderedBasicBlocks where
|
|
|
|
// necessary to compare uses/defs in the same block. Doing so allows us to walk
|
|
|
|
// the minimum number of instructions necessary to compute our def/use ordering.
|
|
|
|
struct ValueDFS_Compare {
|
2017-06-29 19:01:14 +02:00
|
|
|
OrderedInstructions &OI;
|
|
|
|
ValueDFS_Compare(OrderedInstructions &OI) : OI(OI) {}
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
bool operator()(const ValueDFS &A, const ValueDFS &B) const {
|
|
|
|
if (&A == &B)
|
|
|
|
return false;
|
|
|
|
// The only case we can't directly compare them is when they in the same
|
|
|
|
// block, and both have localnum == middle. In that case, we have to use
|
|
|
|
// comesbefore to see what the real ordering is, because they are in the
|
|
|
|
// same basic block.
|
|
|
|
|
|
|
|
bool SameBlock = std::tie(A.DFSIn, A.DFSOut) == std::tie(B.DFSIn, B.DFSOut);
|
|
|
|
|
2017-02-12 23:12:20 +01:00
|
|
|
// We want to put the def that will get used for a given set of phi uses,
|
|
|
|
// before those phi uses.
|
|
|
|
// So we sort by edge, then by def.
|
|
|
|
// Note that only phi nodes uses and defs can come last.
|
|
|
|
if (SameBlock && A.LocalNum == LN_Last && B.LocalNum == LN_Last)
|
|
|
|
return comparePHIRelated(A, B);
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (!SameBlock || A.LocalNum != LN_Middle || B.LocalNum != LN_Middle)
|
2017-02-07 23:11:43 +01:00
|
|
|
return std::tie(A.DFSIn, A.DFSOut, A.LocalNum, A.Def, A.U) <
|
|
|
|
std::tie(B.DFSIn, B.DFSOut, B.LocalNum, B.Def, B.U);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
return localComesBefore(A, B);
|
|
|
|
}
|
|
|
|
|
2017-02-12 23:12:20 +01:00
|
|
|
// For a phi use, or a non-materialized def, return the edge it represents.
|
2017-02-22 23:20:58 +01:00
|
|
|
const std::pair<BasicBlock *, BasicBlock *>
|
2017-02-12 23:12:20 +01:00
|
|
|
getBlockEdge(const ValueDFS &VD) const {
|
|
|
|
if (!VD.Def && VD.U) {
|
|
|
|
auto *PHI = cast<PHINode>(VD.U->getUser());
|
|
|
|
return std::make_pair(PHI->getIncomingBlock(*VD.U), PHI->getParent());
|
|
|
|
}
|
|
|
|
// This is really a non-materialized def.
|
2017-02-22 23:20:58 +01:00
|
|
|
return ::getBlockEdge(VD.PInfo);
|
2017-02-12 23:12:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// For two phi related values, return the ordering.
|
|
|
|
bool comparePHIRelated(const ValueDFS &A, const ValueDFS &B) const {
|
|
|
|
auto &ABlockEdge = getBlockEdge(A);
|
|
|
|
auto &BBlockEdge = getBlockEdge(B);
|
|
|
|
// Now sort by block edge and then defs before uses.
|
|
|
|
return std::tie(ABlockEdge, A.Def, A.U) < std::tie(BBlockEdge, B.Def, B.U);
|
|
|
|
}
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
// Get the definition of an instruction that occurs in the middle of a block.
|
|
|
|
Value *getMiddleDef(const ValueDFS &VD) const {
|
|
|
|
if (VD.Def)
|
|
|
|
return VD.Def;
|
|
|
|
// It's possible for the defs and uses to be null. For branches, the local
|
|
|
|
// numbering will say the placed predicaeinfos should go first (IE
|
|
|
|
// LN_beginning), so we won't be in this function. For assumes, we will end
|
|
|
|
// up here, beause we need to order the def we will place relative to the
|
|
|
|
// assume. So for the purpose of ordering, we pretend the def is the assume
|
|
|
|
// because that is where we will insert the info.
|
2017-02-07 23:11:43 +01:00
|
|
|
if (!VD.U) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
assert(VD.PInfo &&
|
|
|
|
"No def, no use, and no predicateinfo should not occur");
|
|
|
|
assert(isa<PredicateAssume>(VD.PInfo) &&
|
|
|
|
"Middle of block should only occur for assumes");
|
|
|
|
return cast<PredicateAssume>(VD.PInfo)->AssumeInst;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return either the Def, if it's not null, or the user of the Use, if the def
|
|
|
|
// is null.
|
2017-02-07 23:11:43 +01:00
|
|
|
const Instruction *getDefOrUser(const Value *Def, const Use *U) const {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (Def)
|
|
|
|
return cast<Instruction>(Def);
|
2017-02-07 23:11:43 +01:00
|
|
|
return cast<Instruction>(U->getUser());
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// This performs the necessary local basic block ordering checks to tell
|
|
|
|
// whether A comes before B, where both are in the same basic block.
|
|
|
|
bool localComesBefore(const ValueDFS &A, const ValueDFS &B) const {
|
|
|
|
auto *ADef = getMiddleDef(A);
|
|
|
|
auto *BDef = getMiddleDef(B);
|
|
|
|
|
|
|
|
// See if we have real values or uses. If we have real values, we are
|
|
|
|
// guaranteed they are instructions or arguments. No matter what, we are
|
|
|
|
// guaranteed they are in the same block if they are instructions.
|
|
|
|
auto *ArgA = dyn_cast_or_null<Argument>(ADef);
|
|
|
|
auto *ArgB = dyn_cast_or_null<Argument>(BDef);
|
|
|
|
|
2017-06-29 19:01:14 +02:00
|
|
|
if (ArgA || ArgB)
|
|
|
|
return valueComesBefore(OI, ArgA, ArgB);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
2017-02-07 23:11:43 +01:00
|
|
|
auto *AInst = getDefOrUser(ADef, A.U);
|
|
|
|
auto *BInst = getDefOrUser(BDef, B.U);
|
2017-06-29 19:01:14 +02:00
|
|
|
return valueComesBefore(OI, AInst, BInst);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-10-11 23:56:44 +02:00
|
|
|
} // namespace PredicateInfoClasses
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
2017-02-12 23:12:20 +01:00
|
|
|
bool PredicateInfo::stackIsInScope(const ValueDFSStack &Stack,
|
|
|
|
const ValueDFS &VDUse) const {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (Stack.empty())
|
|
|
|
return false;
|
2017-02-12 23:12:20 +01:00
|
|
|
// If it's a phi only use, make sure it's for this phi node edge, and that the
|
|
|
|
// use is in a phi node. If it's anything else, and the top of the stack is
|
2017-02-19 00:06:38 +01:00
|
|
|
// EdgeOnly, we need to pop the stack. We deliberately sort phi uses next to
|
2017-02-12 23:12:20 +01:00
|
|
|
// the defs they must go with so that we can know it's time to pop the stack
|
|
|
|
// when we hit the end of the phi uses for a given def.
|
2017-02-19 00:06:38 +01:00
|
|
|
if (Stack.back().EdgeOnly) {
|
2017-02-12 23:12:20 +01:00
|
|
|
if (!VDUse.U)
|
|
|
|
return false;
|
|
|
|
auto *PHI = dyn_cast<PHINode>(VDUse.U->getUser());
|
|
|
|
if (!PHI)
|
|
|
|
return false;
|
2017-02-22 23:20:58 +01:00
|
|
|
// Check edge
|
2017-02-12 23:12:20 +01:00
|
|
|
BasicBlock *EdgePred = PHI->getIncomingBlock(*VDUse.U);
|
2017-02-22 23:20:58 +01:00
|
|
|
if (EdgePred != getBranchBlock(Stack.back().PInfo))
|
2017-02-12 23:12:20 +01:00
|
|
|
return false;
|
2017-02-19 00:06:38 +01:00
|
|
|
|
|
|
|
// Use dominates, which knows how to handle edge dominance.
|
2017-02-22 23:20:58 +01:00
|
|
|
return DT.dominates(getBlockEdge(Stack.back().PInfo), *VDUse.U);
|
2017-02-12 23:12:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (VDUse.DFSIn >= Stack.back().DFSIn &&
|
|
|
|
VDUse.DFSOut <= Stack.back().DFSOut);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
|
2017-02-12 23:12:20 +01:00
|
|
|
void PredicateInfo::popStackUntilDFSScope(ValueDFSStack &Stack,
|
|
|
|
const ValueDFS &VD) {
|
|
|
|
while (!Stack.empty() && !stackIsInScope(Stack, VD))
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
Stack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the uses of Op into a vector of uses, associating global and local
|
|
|
|
// DFS info with each one.
|
|
|
|
void PredicateInfo::convertUsesToDFSOrdered(
|
|
|
|
Value *Op, SmallVectorImpl<ValueDFS> &DFSOrderedSet) {
|
|
|
|
for (auto &U : Op->uses()) {
|
|
|
|
if (auto *I = dyn_cast<Instruction>(U.getUser())) {
|
|
|
|
ValueDFS VD;
|
|
|
|
// Put the phi node uses in the incoming block.
|
|
|
|
BasicBlock *IBlock;
|
|
|
|
if (auto *PN = dyn_cast<PHINode>(I)) {
|
|
|
|
IBlock = PN->getIncomingBlock(U);
|
|
|
|
// Make phi node users appear last in the incoming block
|
|
|
|
// they are from.
|
|
|
|
VD.LocalNum = LN_Last;
|
|
|
|
} else {
|
|
|
|
// If it's not a phi node use, it is somewhere in the middle of the
|
|
|
|
// block.
|
|
|
|
IBlock = I->getParent();
|
|
|
|
VD.LocalNum = LN_Middle;
|
|
|
|
}
|
|
|
|
DomTreeNode *DomNode = DT.getNode(IBlock);
|
|
|
|
// It's possible our use is in an unreachable block. Skip it if so.
|
|
|
|
if (!DomNode)
|
|
|
|
continue;
|
|
|
|
VD.DFSIn = DomNode->getDFSNumIn();
|
|
|
|
VD.DFSOut = DomNode->getDFSNumOut();
|
2017-02-07 23:11:43 +01:00
|
|
|
VD.U = &U;
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
DFSOrderedSet.push_back(VD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect relevant operations from Comparison that we may want to insert copies
|
|
|
|
// for.
|
2017-10-11 23:56:44 +02:00
|
|
|
void collectCmpOps(CmpInst *Comparison, SmallVectorImpl<Value *> &CmpOperands) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
auto *Op0 = Comparison->getOperand(0);
|
|
|
|
auto *Op1 = Comparison->getOperand(1);
|
|
|
|
if (Op0 == Op1)
|
|
|
|
return;
|
|
|
|
CmpOperands.push_back(Comparison);
|
|
|
|
// Only want real values, not constants. Additionally, operands with one use
|
|
|
|
// are only being used in the comparison, which means they will not be useful
|
|
|
|
// for us to consider for predicateinfo.
|
|
|
|
//
|
2017-02-19 00:06:38 +01:00
|
|
|
if ((isa<Instruction>(Op0) || isa<Argument>(Op0)) && !Op0->hasOneUse())
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
CmpOperands.push_back(Op0);
|
2017-02-19 00:06:38 +01:00
|
|
|
if ((isa<Instruction>(Op1) || isa<Argument>(Op1)) && !Op1->hasOneUse())
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
CmpOperands.push_back(Op1);
|
|
|
|
}
|
|
|
|
|
2017-02-19 00:06:38 +01:00
|
|
|
// Add Op, PB to the list of value infos for Op, and mark Op to be renamed.
|
|
|
|
void PredicateInfo::addInfoFor(SmallPtrSetImpl<Value *> &OpsToRename, Value *Op,
|
|
|
|
PredicateBase *PB) {
|
|
|
|
OpsToRename.insert(Op);
|
|
|
|
auto &OperandInfo = getOrCreateValueInfo(Op);
|
|
|
|
AllInfos.push_back(PB);
|
|
|
|
OperandInfo.Infos.push_back(PB);
|
|
|
|
}
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
// Process an assume instruction and place relevant operations we want to rename
|
|
|
|
// into OpsToRename.
|
|
|
|
void PredicateInfo::processAssume(IntrinsicInst *II, BasicBlock *AssumeBB,
|
|
|
|
SmallPtrSetImpl<Value *> &OpsToRename) {
|
2017-02-19 00:06:38 +01:00
|
|
|
// See if we have a comparison we support
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
SmallVector<Value *, 8> CmpOperands;
|
2017-02-19 00:06:38 +01:00
|
|
|
SmallVector<Value *, 2> ConditionsToProcess;
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
CmpInst::Predicate Pred;
|
|
|
|
Value *Operand = II->getOperand(0);
|
|
|
|
if (m_c_And(m_Cmp(Pred, m_Value(), m_Value()),
|
|
|
|
m_Cmp(Pred, m_Value(), m_Value()))
|
|
|
|
.match(II->getOperand(0))) {
|
2017-02-19 00:06:38 +01:00
|
|
|
ConditionsToProcess.push_back(cast<BinaryOperator>(Operand)->getOperand(0));
|
|
|
|
ConditionsToProcess.push_back(cast<BinaryOperator>(Operand)->getOperand(1));
|
|
|
|
ConditionsToProcess.push_back(Operand);
|
|
|
|
} else if (isa<CmpInst>(Operand)) {
|
|
|
|
|
|
|
|
ConditionsToProcess.push_back(Operand);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
2017-02-19 00:06:38 +01:00
|
|
|
for (auto Cond : ConditionsToProcess) {
|
|
|
|
if (auto *Cmp = dyn_cast<CmpInst>(Cond)) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
collectCmpOps(Cmp, CmpOperands);
|
|
|
|
// Now add our copy infos for our operands
|
|
|
|
for (auto *Op : CmpOperands) {
|
2017-02-19 00:06:38 +01:00
|
|
|
auto *PA = new PredicateAssume(Op, II, Cmp);
|
|
|
|
addInfoFor(OpsToRename, Op, PA);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
CmpOperands.clear();
|
2017-02-19 00:06:38 +01:00
|
|
|
} else if (auto *BinOp = dyn_cast<BinaryOperator>(Cond)) {
|
|
|
|
// Otherwise, it should be an AND.
|
|
|
|
assert(BinOp->getOpcode() == Instruction::And &&
|
2017-02-19 01:33:37 +01:00
|
|
|
"Should have been an AND");
|
|
|
|
auto *PA = new PredicateAssume(BinOp, II, BinOp);
|
|
|
|
addInfoFor(OpsToRename, BinOp, PA);
|
2017-02-19 00:06:38 +01:00
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unknown type of condition");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process a block terminating branch, and place relevant operations to be
|
|
|
|
// renamed into OpsToRename.
|
|
|
|
void PredicateInfo::processBranch(BranchInst *BI, BasicBlock *BranchBB,
|
|
|
|
SmallPtrSetImpl<Value *> &OpsToRename) {
|
|
|
|
BasicBlock *FirstBB = BI->getSuccessor(0);
|
|
|
|
BasicBlock *SecondBB = BI->getSuccessor(1);
|
|
|
|
SmallVector<BasicBlock *, 2> SuccsToProcess;
|
2017-02-12 23:12:20 +01:00
|
|
|
SuccsToProcess.push_back(FirstBB);
|
|
|
|
SuccsToProcess.push_back(SecondBB);
|
2017-02-19 00:06:38 +01:00
|
|
|
SmallVector<Value *, 2> ConditionsToProcess;
|
|
|
|
|
|
|
|
auto InsertHelper = [&](Value *Op, bool isAnd, bool isOr, Value *Cond) {
|
|
|
|
for (auto *Succ : SuccsToProcess) {
|
|
|
|
// Don't try to insert on a self-edge. This is mainly because we will
|
|
|
|
// eliminate during renaming anyway.
|
|
|
|
if (Succ == BranchBB)
|
|
|
|
continue;
|
|
|
|
bool TakenEdge = (Succ == FirstBB);
|
|
|
|
// For and, only insert on the true edge
|
|
|
|
// For or, only insert on the false edge
|
|
|
|
if ((isAnd && !TakenEdge) || (isOr && TakenEdge))
|
|
|
|
continue;
|
|
|
|
PredicateBase *PB =
|
|
|
|
new PredicateBranch(Op, BranchBB, Succ, Cond, TakenEdge);
|
|
|
|
addInfoFor(OpsToRename, Op, PB);
|
|
|
|
if (!Succ->getSinglePredecessor())
|
|
|
|
EdgeUsesOnly.insert({BranchBB, Succ});
|
|
|
|
}
|
|
|
|
};
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
|
|
|
// Match combinations of conditions.
|
2017-02-19 00:06:38 +01:00
|
|
|
CmpInst::Predicate Pred;
|
|
|
|
bool isAnd = false;
|
|
|
|
bool isOr = false;
|
|
|
|
SmallVector<Value *, 8> CmpOperands;
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (match(BI->getCondition(), m_And(m_Cmp(Pred, m_Value(), m_Value()),
|
|
|
|
m_Cmp(Pred, m_Value(), m_Value()))) ||
|
|
|
|
match(BI->getCondition(), m_Or(m_Cmp(Pred, m_Value(), m_Value()),
|
|
|
|
m_Cmp(Pred, m_Value(), m_Value())))) {
|
|
|
|
auto *BinOp = cast<BinaryOperator>(BI->getCondition());
|
|
|
|
if (BinOp->getOpcode() == Instruction::And)
|
|
|
|
isAnd = true;
|
|
|
|
else if (BinOp->getOpcode() == Instruction::Or)
|
|
|
|
isOr = true;
|
2017-02-19 00:06:38 +01:00
|
|
|
ConditionsToProcess.push_back(BinOp->getOperand(0));
|
|
|
|
ConditionsToProcess.push_back(BinOp->getOperand(1));
|
|
|
|
ConditionsToProcess.push_back(BI->getCondition());
|
|
|
|
} else if (isa<CmpInst>(BI->getCondition())) {
|
|
|
|
ConditionsToProcess.push_back(BI->getCondition());
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
2017-02-19 00:06:38 +01:00
|
|
|
for (auto Cond : ConditionsToProcess) {
|
|
|
|
if (auto *Cmp = dyn_cast<CmpInst>(Cond)) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
collectCmpOps(Cmp, CmpOperands);
|
|
|
|
// Now add our copy infos for our operands
|
2017-02-19 00:06:38 +01:00
|
|
|
for (auto *Op : CmpOperands)
|
|
|
|
InsertHelper(Op, isAnd, isOr, Cmp);
|
|
|
|
} else if (auto *BinOp = dyn_cast<BinaryOperator>(Cond)) {
|
|
|
|
// This must be an AND or an OR.
|
|
|
|
assert((BinOp->getOpcode() == Instruction::And ||
|
|
|
|
BinOp->getOpcode() == Instruction::Or) &&
|
|
|
|
"Should have been an AND or an OR");
|
|
|
|
// The actual value of the binop is not subject to the same restrictions
|
|
|
|
// as the comparison. It's either true or false on the true/false branch.
|
2017-02-19 01:33:37 +01:00
|
|
|
InsertHelper(BinOp, false, false, BinOp);
|
2017-02-19 00:06:38 +01:00
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unknown type of condition");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
2017-02-19 00:06:38 +01:00
|
|
|
CmpOperands.clear();
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 23:20:58 +01:00
|
|
|
// Process a block terminating switch, and place relevant operations to be
|
|
|
|
// renamed into OpsToRename.
|
|
|
|
void PredicateInfo::processSwitch(SwitchInst *SI, BasicBlock *BranchBB,
|
|
|
|
SmallPtrSetImpl<Value *> &OpsToRename) {
|
|
|
|
Value *Op = SI->getCondition();
|
|
|
|
if ((!isa<Instruction>(Op) && !isa<Argument>(Op)) || Op->hasOneUse())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remember how many outgoing edges there are to every successor.
|
|
|
|
SmallDenseMap<BasicBlock *, unsigned, 16> SwitchEdges;
|
|
|
|
for (unsigned i = 0, e = SI->getNumSuccessors(); i != e; ++i) {
|
|
|
|
BasicBlock *TargetBlock = SI->getSuccessor(i);
|
|
|
|
++SwitchEdges[TargetBlock];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now propagate info for each case value
|
|
|
|
for (auto C : SI->cases()) {
|
|
|
|
BasicBlock *TargetBlock = C.getCaseSuccessor();
|
|
|
|
if (SwitchEdges.lookup(TargetBlock) == 1) {
|
|
|
|
PredicateSwitch *PS = new PredicateSwitch(
|
|
|
|
Op, SI->getParent(), TargetBlock, C.getCaseValue(), SI);
|
|
|
|
addInfoFor(OpsToRename, Op, PS);
|
|
|
|
if (!TargetBlock->getSinglePredecessor())
|
|
|
|
EdgeUsesOnly.insert({BranchBB, TargetBlock});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
|
|
|
// Build predicate info for our function
|
|
|
|
void PredicateInfo::buildPredicateInfo() {
|
|
|
|
DT.updateDFSNumbers();
|
|
|
|
// Collect operands to rename from all conditional branch terminators, as well
|
|
|
|
// as assume statements.
|
|
|
|
SmallPtrSet<Value *, 8> OpsToRename;
|
|
|
|
for (auto DTN : depth_first(DT.getRootNode())) {
|
|
|
|
BasicBlock *BranchBB = DTN->getBlock();
|
|
|
|
if (auto *BI = dyn_cast<BranchInst>(BranchBB->getTerminator())) {
|
|
|
|
if (!BI->isConditional())
|
|
|
|
continue;
|
2017-06-14 23:19:52 +02:00
|
|
|
// Can't insert conditional information if they all go to the same place.
|
|
|
|
if (BI->getSuccessor(0) == BI->getSuccessor(1))
|
|
|
|
continue;
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
processBranch(BI, BranchBB, OpsToRename);
|
2017-02-22 23:20:58 +01:00
|
|
|
} else if (auto *SI = dyn_cast<SwitchInst>(BranchBB->getTerminator())) {
|
|
|
|
processSwitch(SI, BranchBB, OpsToRename);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto &Assume : AC.assumptions()) {
|
|
|
|
if (auto *II = dyn_cast_or_null<IntrinsicInst>(Assume))
|
2019-05-15 21:35:38 +02:00
|
|
|
if (DT.isReachableFromEntry(II->getParent()))
|
|
|
|
processAssume(II, II->getParent(), OpsToRename);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
// Now rename all our operations.
|
|
|
|
renameUses(OpsToRename);
|
|
|
|
}
|
2017-02-22 23:20:58 +01:00
|
|
|
|
2018-07-24 16:49:52 +02:00
|
|
|
// Create a ssa_copy declaration with custom mangling, because
|
|
|
|
// Intrinsic::getDeclaration does not handle overloaded unnamed types properly:
|
|
|
|
// all unnamed types get mangled to the same string. We use the pointer
|
|
|
|
// to the type as name here, as it guarantees unique names for different
|
|
|
|
// types and we remove the declarations when destroying PredicateInfo.
|
|
|
|
// It is a workaround for PR38117, because solving it in a fully general way is
|
|
|
|
// tricky (FIXME).
|
|
|
|
static Function *getCopyDeclaration(Module *M, Type *Ty) {
|
|
|
|
std::string Name = "llvm.ssa.copy." + utostr((uintptr_t) Ty);
|
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
2019-02-01 03:28:03 +01:00
|
|
|
return cast<Function>(
|
|
|
|
M->getOrInsertFunction(Name,
|
|
|
|
getType(M->getContext(), Intrinsic::ssa_copy, Ty))
|
|
|
|
.getCallee());
|
2018-07-24 16:49:52 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 23:20:58 +01:00
|
|
|
// Given the renaming stack, make all the operands currently on the stack real
|
|
|
|
// by inserting them into the IR. Return the last operation's value.
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
Value *PredicateInfo::materializeStack(unsigned int &Counter,
|
|
|
|
ValueDFSStack &RenameStack,
|
|
|
|
Value *OrigOp) {
|
|
|
|
// Find the first thing we have to materialize
|
|
|
|
auto RevIter = RenameStack.rbegin();
|
|
|
|
for (; RevIter != RenameStack.rend(); ++RevIter)
|
|
|
|
if (RevIter->Def)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size_t Start = RevIter - RenameStack.rbegin();
|
|
|
|
// The maximum number of things we should be trying to materialize at once
|
|
|
|
// right now is 4, depending on if we had an assume, a branch, and both used
|
|
|
|
// and of conditions.
|
|
|
|
for (auto RenameIter = RenameStack.end() - Start;
|
|
|
|
RenameIter != RenameStack.end(); ++RenameIter) {
|
|
|
|
auto *Op =
|
|
|
|
RenameIter == RenameStack.begin() ? OrigOp : (RenameIter - 1)->Def;
|
|
|
|
ValueDFS &Result = *RenameIter;
|
|
|
|
auto *ValInfo = Result.PInfo;
|
2017-02-22 23:20:58 +01:00
|
|
|
// For edge predicates, we can just place the operand in the block before
|
2017-02-12 23:12:20 +01:00
|
|
|
// the terminator. For assume, we have to place it right before the assume
|
|
|
|
// to ensure we dominate all of our uses. Always insert right before the
|
|
|
|
// relevant instruction (terminator, assume), so that we insert in proper
|
|
|
|
// order in the case of multiple predicateinfo in the same block.
|
2017-02-22 23:20:58 +01:00
|
|
|
if (isa<PredicateWithEdge>(ValInfo)) {
|
|
|
|
IRBuilder<> B(getBranchTerminator(ValInfo));
|
2018-07-24 16:49:52 +02:00
|
|
|
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
|
2018-10-31 01:23:23 +01:00
|
|
|
if (empty(IF->users()))
|
2018-07-24 16:49:52 +02:00
|
|
|
CreatedDeclarations.insert(IF);
|
2017-02-19 00:06:38 +01:00
|
|
|
CallInst *PIC =
|
|
|
|
B.CreateCall(IF, Op, Op->getName() + "." + Twine(Counter++));
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
PredicateMap.insert({PIC, ValInfo});
|
|
|
|
Result.Def = PIC;
|
|
|
|
} else {
|
|
|
|
auto *PAssume = dyn_cast<PredicateAssume>(ValInfo);
|
|
|
|
assert(PAssume &&
|
|
|
|
"Should not have gotten here without it being an assume");
|
2017-02-12 23:12:20 +01:00
|
|
|
IRBuilder<> B(PAssume->AssumeInst);
|
2018-07-24 16:49:52 +02:00
|
|
|
Function *IF = getCopyDeclaration(F.getParent(), Op->getType());
|
2018-10-31 01:23:23 +01:00
|
|
|
if (empty(IF->users()))
|
2018-07-24 16:49:52 +02:00
|
|
|
CreatedDeclarations.insert(IF);
|
2017-02-19 00:06:38 +01:00
|
|
|
CallInst *PIC = B.CreateCall(IF, Op);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
PredicateMap.insert({PIC, ValInfo});
|
|
|
|
Result.Def = PIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RenameStack.back().Def;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instead of the standard SSA renaming algorithm, which is O(Number of
|
|
|
|
// instructions), and walks the entire dominator tree, we walk only the defs +
|
|
|
|
// uses. The standard SSA renaming algorithm does not really rely on the
|
|
|
|
// dominator tree except to order the stack push/pops of the renaming stacks, so
|
|
|
|
// that defs end up getting pushed before hitting the correct uses. This does
|
|
|
|
// not require the dominator tree, only the *order* of the dominator tree. The
|
|
|
|
// complete and correct ordering of the defs and uses, in dominator tree is
|
|
|
|
// contained in the DFS numbering of the dominator tree. So we sort the defs and
|
|
|
|
// uses into the DFS ordering, and then just use the renaming stack as per
|
|
|
|
// normal, pushing when we hit a def (which is a predicateinfo instruction),
|
|
|
|
// popping when we are out of the dfs scope for that def, and replacing any uses
|
|
|
|
// with top of stack if it exists. In order to handle liveness without
|
|
|
|
// propagating liveness info, we don't actually insert the predicateinfo
|
|
|
|
// instruction def until we see a use that it would dominate. Once we see such
|
|
|
|
// a use, we materialize the predicateinfo instruction in the right place and
|
|
|
|
// use it.
|
|
|
|
//
|
|
|
|
// TODO: Use this algorithm to perform fast single-variable renaming in
|
|
|
|
// promotememtoreg and memoryssa.
|
2017-06-01 20:36:24 +02:00
|
|
|
void PredicateInfo::renameUses(SmallPtrSetImpl<Value *> &OpSet) {
|
|
|
|
// Sort OpsToRename since we are going to iterate it.
|
|
|
|
SmallVector<Value *, 8> OpsToRename(OpSet.begin(), OpSet.end());
|
2017-06-29 19:01:14 +02:00
|
|
|
auto Comparator = [&](const Value *A, const Value *B) {
|
|
|
|
return valueComesBefore(OI, A, B);
|
|
|
|
};
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 04:13:45 +02:00
|
|
|
llvm::sort(OpsToRename, Comparator);
|
2017-06-29 19:01:14 +02:00
|
|
|
ValueDFS_Compare Compare(OI);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
// Compute liveness, and rename in O(uses) per Op.
|
|
|
|
for (auto *Op : OpsToRename) {
|
2018-06-20 19:42:01 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Visiting " << *Op << "\n");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
unsigned Counter = 0;
|
|
|
|
SmallVector<ValueDFS, 16> OrderedUses;
|
|
|
|
const auto &ValueInfo = getValueInfo(Op);
|
|
|
|
// Insert the possible copies into the def/use list.
|
|
|
|
// They will become real copies if we find a real use for them, and never
|
|
|
|
// created otherwise.
|
|
|
|
for (auto &PossibleCopy : ValueInfo.Infos) {
|
|
|
|
ValueDFS VD;
|
|
|
|
// Determine where we are going to place the copy by the copy type.
|
|
|
|
// The predicate info for branches always come first, they will get
|
|
|
|
// materialized in the split block at the top of the block.
|
|
|
|
// The predicate info for assumes will be somewhere in the middle,
|
|
|
|
// it will get materialized in front of the assume.
|
2017-02-12 23:12:20 +01:00
|
|
|
if (const auto *PAssume = dyn_cast<PredicateAssume>(PossibleCopy)) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
VD.LocalNum = LN_Middle;
|
2017-02-12 23:12:20 +01:00
|
|
|
DomTreeNode *DomNode = DT.getNode(PAssume->AssumeInst->getParent());
|
|
|
|
if (!DomNode)
|
|
|
|
continue;
|
|
|
|
VD.DFSIn = DomNode->getDFSNumIn();
|
|
|
|
VD.DFSOut = DomNode->getDFSNumOut();
|
|
|
|
VD.PInfo = PossibleCopy;
|
|
|
|
OrderedUses.push_back(VD);
|
2017-02-22 23:20:58 +01:00
|
|
|
} else if (isa<PredicateWithEdge>(PossibleCopy)) {
|
2017-02-12 23:12:20 +01:00
|
|
|
// If we can only do phi uses, we treat it like it's in the branch
|
|
|
|
// block, and handle it specially. We know that it goes last, and only
|
|
|
|
// dominate phi uses.
|
2017-02-22 23:20:58 +01:00
|
|
|
auto BlockEdge = getBlockEdge(PossibleCopy);
|
|
|
|
if (EdgeUsesOnly.count(BlockEdge)) {
|
2017-02-12 23:12:20 +01:00
|
|
|
VD.LocalNum = LN_Last;
|
2017-02-22 23:20:58 +01:00
|
|
|
auto *DomNode = DT.getNode(BlockEdge.first);
|
2017-02-12 23:12:20 +01:00
|
|
|
if (DomNode) {
|
|
|
|
VD.DFSIn = DomNode->getDFSNumIn();
|
|
|
|
VD.DFSOut = DomNode->getDFSNumOut();
|
|
|
|
VD.PInfo = PossibleCopy;
|
2017-02-19 00:06:38 +01:00
|
|
|
VD.EdgeOnly = true;
|
2017-02-12 23:12:20 +01:00
|
|
|
OrderedUses.push_back(VD);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, we are in the split block (even though we perform
|
|
|
|
// insertion in the branch block).
|
|
|
|
// Insert a possible copy at the split block and before the branch.
|
|
|
|
VD.LocalNum = LN_First;
|
2017-02-22 23:20:58 +01:00
|
|
|
auto *DomNode = DT.getNode(BlockEdge.second);
|
2017-02-12 23:12:20 +01:00
|
|
|
if (DomNode) {
|
|
|
|
VD.DFSIn = DomNode->getDFSNumIn();
|
|
|
|
VD.DFSOut = DomNode->getDFSNumOut();
|
|
|
|
VD.PInfo = PossibleCopy;
|
|
|
|
OrderedUses.push_back(VD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
convertUsesToDFSOrdered(Op, OrderedUses);
|
2017-11-17 01:43:24 +01:00
|
|
|
// Here we require a stable sort because we do not bother to try to
|
|
|
|
// assign an order to the operands the uses represent. Thus, two
|
|
|
|
// uses in the same instruction do not have a strict sort order
|
|
|
|
// currently and will be considered equal. We could get rid of the
|
|
|
|
// stable sort by creating one if we wanted.
|
2019-04-23 16:51:27 +02:00
|
|
|
llvm::stable_sort(OrderedUses, Compare);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
SmallVector<ValueDFS, 8> RenameStack;
|
|
|
|
// For each use, sorted into dfs order, push values and replaces uses with
|
|
|
|
// top of stack, which will represent the reaching def.
|
|
|
|
for (auto &VD : OrderedUses) {
|
|
|
|
// We currently do not materialize copy over copy, but we should decide if
|
|
|
|
// we want to.
|
|
|
|
bool PossibleCopy = VD.PInfo != nullptr;
|
|
|
|
if (RenameStack.empty()) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Rename Stack is empty\n");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
} else {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Rename Stack Top DFS numbers are ("
|
|
|
|
<< RenameStack.back().DFSIn << ","
|
|
|
|
<< RenameStack.back().DFSOut << ")\n");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Current DFS numbers are (" << VD.DFSIn << ","
|
|
|
|
<< VD.DFSOut << ")\n");
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
|
|
|
bool ShouldPush = (VD.Def || PossibleCopy);
|
2017-02-12 23:12:20 +01:00
|
|
|
bool OutOfScope = !stackIsInScope(RenameStack, VD);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (OutOfScope || ShouldPush) {
|
|
|
|
// Sync to our current scope.
|
2017-02-12 23:12:20 +01:00
|
|
|
popStackUntilDFSScope(RenameStack, VD);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (ShouldPush) {
|
|
|
|
RenameStack.push_back(VD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we get to this point, and the stack is empty we must have a use
|
|
|
|
// with no renaming needed, just skip it.
|
|
|
|
if (RenameStack.empty())
|
|
|
|
continue;
|
|
|
|
// Skip values, only want to rename the uses
|
|
|
|
if (VD.Def || PossibleCopy)
|
|
|
|
continue;
|
2017-02-19 05:29:01 +01:00
|
|
|
if (!DebugCounter::shouldExecute(RenameCounter)) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Skipping execution due to debug counter\n");
|
2017-02-19 05:29:01 +01:00
|
|
|
continue;
|
|
|
|
}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
ValueDFS &Result = RenameStack.back();
|
|
|
|
|
|
|
|
// If the possible copy dominates something, materialize our stack up to
|
|
|
|
// this point. This ensures every comparison that affects our operation
|
|
|
|
// ends up with predicateinfo.
|
|
|
|
if (!Result.Def)
|
|
|
|
Result.Def = materializeStack(Counter, RenameStack, Op);
|
|
|
|
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(dbgs() << "Found replacement " << *Result.Def << " for "
|
|
|
|
<< *VD.U->get() << " in " << *(VD.U->getUser())
|
|
|
|
<< "\n");
|
2017-02-07 23:11:43 +01:00
|
|
|
assert(DT.dominates(cast<Instruction>(Result.Def), *VD.U) &&
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
"Predicateinfo def should have dominated this use");
|
2017-02-07 23:11:43 +01:00
|
|
|
VD.U->set(Result.Def);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PredicateInfo::ValueInfo &PredicateInfo::getOrCreateValueInfo(Value *Operand) {
|
|
|
|
auto OIN = ValueInfoNums.find(Operand);
|
|
|
|
if (OIN == ValueInfoNums.end()) {
|
|
|
|
// This will grow it
|
|
|
|
ValueInfos.resize(ValueInfos.size() + 1);
|
|
|
|
// This will use the new size and give us a 0 based number of the info
|
|
|
|
auto InsertResult = ValueInfoNums.insert({Operand, ValueInfos.size() - 1});
|
|
|
|
assert(InsertResult.second && "Value info number already existed?");
|
|
|
|
return ValueInfos[InsertResult.first->second];
|
|
|
|
}
|
|
|
|
return ValueInfos[OIN->second];
|
|
|
|
}
|
|
|
|
|
|
|
|
const PredicateInfo::ValueInfo &
|
|
|
|
PredicateInfo::getValueInfo(Value *Operand) const {
|
|
|
|
auto OINI = ValueInfoNums.lookup(Operand);
|
|
|
|
assert(OINI != 0 && "Operand was not really in the Value Info Numbers");
|
|
|
|
assert(OINI < ValueInfos.size() &&
|
|
|
|
"Value Info Number greater than size of Value Info Table");
|
|
|
|
return ValueInfos[OINI];
|
|
|
|
}
|
|
|
|
|
|
|
|
PredicateInfo::PredicateInfo(Function &F, DominatorTree &DT,
|
|
|
|
AssumptionCache &AC)
|
2017-06-29 19:01:14 +02:00
|
|
|
: F(F), DT(DT), AC(AC), OI(&DT) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
// Push an empty operand info so that we can detect 0 as not finding one
|
|
|
|
ValueInfos.resize(1);
|
|
|
|
buildPredicateInfo();
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:49:52 +02:00
|
|
|
// Remove all declarations we created . The PredicateInfo consumers are
|
|
|
|
// responsible for remove the ssa_copy calls created.
|
|
|
|
PredicateInfo::~PredicateInfo() {
|
|
|
|
// Collect function pointers in set first, as SmallSet uses a SmallVector
|
|
|
|
// internally and we have to remove the asserting value handles first.
|
|
|
|
SmallPtrSet<Function *, 20> FunctionPtrs;
|
|
|
|
for (auto &F : CreatedDeclarations)
|
|
|
|
FunctionPtrs.insert(&*F);
|
|
|
|
CreatedDeclarations.clear();
|
|
|
|
|
|
|
|
for (Function *F : FunctionPtrs) {
|
|
|
|
assert(F->user_begin() == F->user_end() &&
|
|
|
|
"PredicateInfo consumer did not remove all SSA copies.");
|
|
|
|
F->eraseFromParent();
|
|
|
|
}
|
|
|
|
}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
|
|
|
void PredicateInfo::verifyPredicateInfo() const {}
|
|
|
|
|
|
|
|
char PredicateInfoPrinterLegacyPass::ID = 0;
|
|
|
|
|
|
|
|
PredicateInfoPrinterLegacyPass::PredicateInfoPrinterLegacyPass()
|
|
|
|
: FunctionPass(ID) {
|
|
|
|
initializePredicateInfoPrinterLegacyPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredicateInfoPrinterLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
|
|
|
|
AU.addRequired<AssumptionCacheTracker>();
|
|
|
|
}
|
|
|
|
|
2018-07-24 16:49:52 +02:00
|
|
|
// Replace ssa_copy calls created by PredicateInfo with their operand.
|
|
|
|
static void replaceCreatedSSACopys(PredicateInfo &PredInfo, Function &F) {
|
|
|
|
for (auto I = inst_begin(F), E = inst_end(F); I != E;) {
|
|
|
|
Instruction *Inst = &*I++;
|
|
|
|
const auto *PI = PredInfo.getPredicateInfoFor(Inst);
|
|
|
|
auto *II = dyn_cast<IntrinsicInst>(Inst);
|
|
|
|
if (!PI || !II || II->getIntrinsicID() != Intrinsic::ssa_copy)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Inst->replaceAllUsesWith(II->getOperand(0));
|
|
|
|
Inst->eraseFromParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
bool PredicateInfoPrinterLegacyPass::runOnFunction(Function &F) {
|
|
|
|
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
|
|
|
auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
|
|
|
|
auto PredInfo = make_unique<PredicateInfo>(F, DT, AC);
|
|
|
|
PredInfo->print(dbgs());
|
|
|
|
if (VerifyPredicateInfo)
|
|
|
|
PredInfo->verifyPredicateInfo();
|
2018-07-24 16:49:52 +02:00
|
|
|
|
|
|
|
replaceCreatedSSACopys(*PredInfo, F);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses PredicateInfoPrinterPass::run(Function &F,
|
|
|
|
FunctionAnalysisManager &AM) {
|
|
|
|
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
|
|
|
auto &AC = AM.getResult<AssumptionAnalysis>(F);
|
|
|
|
OS << "PredicateInfo for function: " << F.getName() << "\n";
|
2018-07-24 16:49:52 +02:00
|
|
|
auto PredInfo = make_unique<PredicateInfo>(F, DT, AC);
|
|
|
|
PredInfo->print(OS);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
2018-07-24 16:49:52 +02:00
|
|
|
replaceCreatedSSACopys(*PredInfo, F);
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// An assembly annotator class to print PredicateInfo information in
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
/// comments.
|
|
|
|
class PredicateInfoAnnotatedWriter : public AssemblyAnnotationWriter {
|
|
|
|
friend class PredicateInfo;
|
|
|
|
const PredicateInfo *PredInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PredicateInfoAnnotatedWriter(const PredicateInfo *M) : PredInfo(M) {}
|
|
|
|
|
2017-10-11 23:56:44 +02:00
|
|
|
virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
|
|
|
|
formatted_raw_ostream &OS) {}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
|
2017-10-11 23:56:44 +02:00
|
|
|
virtual void emitInstructionAnnot(const Instruction *I,
|
|
|
|
formatted_raw_ostream &OS) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
if (const auto *PI = PredInfo->getPredicateInfoFor(I)) {
|
|
|
|
OS << "; Has predicate info\n";
|
2017-02-22 23:20:58 +01:00
|
|
|
if (const auto *PB = dyn_cast<PredicateBranch>(PI)) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
OS << "; branch predicate info { TrueEdge: " << PB->TrueEdge
|
2017-02-22 23:20:58 +01:00
|
|
|
<< " Comparison:" << *PB->Condition << " Edge: [";
|
|
|
|
PB->From->printAsOperand(OS);
|
|
|
|
OS << ",";
|
|
|
|
PB->To->printAsOperand(OS);
|
|
|
|
OS << "] }\n";
|
|
|
|
} else if (const auto *PS = dyn_cast<PredicateSwitch>(PI)) {
|
|
|
|
OS << "; switch predicate info { CaseValue: " << *PS->CaseValue
|
|
|
|
<< " Switch:" << *PS->Switch << " Edge: [";
|
|
|
|
PS->From->printAsOperand(OS);
|
|
|
|
OS << ",";
|
|
|
|
PS->To->printAsOperand(OS);
|
|
|
|
OS << "] }\n";
|
|
|
|
} else if (const auto *PA = dyn_cast<PredicateAssume>(PI)) {
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
OS << "; assume predicate info {"
|
2017-02-19 00:06:38 +01:00
|
|
|
<< " Comparison:" << *PA->Condition << " }\n";
|
2017-02-22 23:20:58 +01:00
|
|
|
}
|
Add PredicateInfo utility and printing pass
Summary:
This patch adds a utility to build extended SSA (see "ABCD: eliminating
array bounds checks on demand"), and an intrinsic to support it. This
is then used to get functionality equivalent to propagateEquality in
GVN, in NewGVN (without having to replace instructions as we go). It
would work similarly in SCCP or other passes. This has been talked
about a few times, so i built a real implementation and tried to
productionize it.
Copies are inserted for operands used in assumes and conditional
branches that are based on comparisons (see below for more)
Every use affected by the predicate is renamed to the appropriate
intrinsic result.
E.g.
%cmp = icmp eq i32 %x, 50
br i1 %cmp, label %true, label %false
true:
ret i32 %x
false:
ret i32 1
will become
%cmp = icmp eq i32, %x, 50
br i1 %cmp, label %true, label %false
true:
; Has predicate info
; branch predicate info { TrueEdge: 1 Comparison: %cmp = icmp eq i32 %x, 50 }
%x.0 = call @llvm.ssa_copy.i32(i32 %x)
ret i32 %x.0
false:
ret i23 1
(you can use -print-predicateinfo to get an annotated-with-predicateinfo dump)
This enables us to easily determine what operations are affected by a
given predicate, and how operations affected by a chain of
predicates.
Reviewers: davide, sanjoy
Subscribers: mgorny, llvm-commits, Prazek
Differential Revision: https://reviews.llvm.org/D29519
Update for review comments
Fix a bug Nuno noticed where we are giving information about and/or on edges where the info is not useful and easy to use wrong
Update for review comments
llvm-svn: 294351
2017-02-07 22:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void PredicateInfo::print(raw_ostream &OS) const {
|
|
|
|
PredicateInfoAnnotatedWriter Writer(this);
|
|
|
|
F.print(OS, &Writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PredicateInfo::dump() const {
|
|
|
|
PredicateInfoAnnotatedWriter Writer(this);
|
|
|
|
F.print(dbgs(), &Writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses PredicateInfoVerifierPass::run(Function &F,
|
|
|
|
FunctionAnalysisManager &AM) {
|
|
|
|
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
|
|
|
auto &AC = AM.getResult<AssumptionAnalysis>(F);
|
|
|
|
make_unique<PredicateInfo>(F, DT, AC)->verifyPredicateInfo();
|
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
2017-10-11 23:56:44 +02:00
|
|
|
}
|