Skip to content

Commit 3ef1aae

Browse files
author
Hal Finkel
committed
Make use of @llvm.assume from LazyValueInfo
This change teaches LazyValueInfo to use the @llvm.assume intrinsic. Like with the known-bits change (r217342), this requires feeding a "context" instruction pointer through many functions. Aside from a little refactoring to reuse the logic that turns predicates into constant ranges in LVI, the only new code is that which can 'merge' the range from an assumption into that otherwise computed. There is also a small addition to JumpThreading so that it can have LVI use assumptions in the same block as the comparison feeding a conditional branch. With this patch, we can now simplify this as expected: int foo(int a) { __builtin_assume(a > 5); if (a > 3) { bar(); return 1; } return 0; } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217345 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1d6c2d7 commit 3ef1aae

File tree

5 files changed

+329
-113
lines changed

5 files changed

+329
-113
lines changed

include/llvm/Analysis/LazyValueInfo.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
#include "llvm/Pass.h"
1919

2020
namespace llvm {
21+
class AssumptionTracker;
2122
class Constant;
2223
class DataLayout;
24+
class DominatorTree;
25+
class Instruction;
2326
class TargetLibraryInfo;
2427
class Value;
2528

2629
/// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
2730
/// information.
2831
class LazyValueInfo : public FunctionPass {
32+
AssumptionTracker *AT;
2933
const DataLayout *DL;
3034
class TargetLibraryInfo *TLI;
35+
DominatorTree *DT;
3136
void *PImpl;
3237
LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
3338
void operator=(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
@@ -50,16 +55,23 @@ class LazyValueInfo : public FunctionPass {
5055
/// with a constant is known to be true or false on the specified CFG edge.
5156
/// Pred is a CmpInst predicate.
5257
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
53-
BasicBlock *FromBB, BasicBlock *ToBB);
54-
58+
BasicBlock *FromBB, BasicBlock *ToBB,
59+
Instruction *CxtI = nullptr);
5560

61+
/// getPredicateAt - Determine whether the specified value comparison
62+
/// with a constant is known to be true or false at the specified instruction
63+
/// (from an assume intrinsic). Pred is a CmpInst predicate.
64+
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
65+
Instruction *CxtI);
66+
5667
/// getConstant - Determine whether the specified value is known to be a
5768
/// constant at the end of the specified block. Return null if not.
58-
Constant *getConstant(Value *V, BasicBlock *BB);
69+
Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
5970

6071
/// getConstantOnEdge - Determine whether the specified value is known to be a
6172
/// constant on the specified edge. Return null if not.
62-
Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB);
73+
Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
74+
Instruction *CxtI = nullptr);
6375

6476
/// threadEdge - Inform the analysis cache that we have threaded an edge from
6577
/// PredBB to OldSucc to be from PredBB to NewSucc instead.

0 commit comments

Comments
 (0)