[llvm] r270500 - [IRCE] Optimize "uses" not branches; NFCI
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Mon May 23 15:16:47 PDT 2016
Author: sanjoy
Date: Mon May 23 17:16:45 2016
New Revision: 270500
URL: http://llvm.org/viewvc/llvm-project?rev=270500&view=rev
Log:
[IRCE] Optimize "uses" not branches; NFCI
This changes IRCE to optimize uses, and not branches. This change is
NFCI since the uses we do inspect are in practice only ever going to be
the condition use in conditional branches; but this flexibility will
later allow us to analyze more complex expressions than just a direct
branch on a range check.
Modified:
llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
llvm/trunk/test/Transforms/IRCE/only-lower-check.ll
llvm/trunk/test/Transforms/IRCE/only-upper-check.ll
Modified: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp?rev=270500&r1=270499&r2=270500&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Mon May 23 17:16:45 2016
@@ -118,7 +118,7 @@ class InductiveRangeCheck {
const SCEV *Offset;
const SCEV *Scale;
Value *Length;
- BranchInst *Branch;
+ Use *CheckUse;
RangeCheckKind Kind;
static RangeCheckKind parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
@@ -129,8 +129,9 @@ class InductiveRangeCheck {
parseRangeCheck(Loop *L, ScalarEvolution &SE, Value *Condition,
const SCEV *&Index, Value *&UpperLimit);
- InductiveRangeCheck() :
- Offset(nullptr), Scale(nullptr), Length(nullptr), Branch(nullptr) { }
+ InductiveRangeCheck()
+ : Offset(nullptr), Scale(nullptr), Length(nullptr),
+ CheckUse(nullptr) {}
public:
const SCEV *getOffset() const { return Offset; }
@@ -149,9 +150,9 @@ public:
Length->print(OS);
else
OS << "(null)";
- OS << "\n Branch: ";
- getBranch()->print(OS);
- OS << "\n";
+ OS << "\n CheckUse: ";
+ getCheckUse()->getUser()->print(OS);
+ OS << " Operand: " << getCheckUse()->getOperandNo() << "\n";
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -160,7 +161,7 @@ public:
}
#endif
- BranchInst *getBranch() const { return Branch; }
+ Use *getCheckUse() const { return CheckUse; }
/// Represents an signed integer range [Range.getBegin(), Range.getEnd()). If
/// R.getEnd() sle R.getBegin(), then R denotes the empty range.
@@ -407,7 +408,7 @@ InductiveRangeCheck::create(BranchInst *
IRC.Length = Length;
IRC.Offset = IndexAddRec->getStart();
IRC.Scale = IndexAddRec->getStepRecurrence(SE);
- IRC.Branch = BI;
+ IRC.CheckUse = &BI->getOperandUse(0);
IRC.Kind = RCKind;
return IRC;
}
@@ -1474,7 +1475,7 @@ bool InductiveRangeCheckElimination::run
ConstantInt *FoldedRangeCheck = IRC.getPassingDirection()
? ConstantInt::getTrue(Context)
: ConstantInt::getFalse(Context);
- IRC.getBranch()->setCondition(FoldedRangeCheck);
+ IRC.getCheckUse()->set(FoldedRangeCheck);
}
}
Modified: llvm/trunk/test/Transforms/IRCE/only-lower-check.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IRCE/only-lower-check.ll?rev=270500&r1=270499&r2=270500&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IRCE/only-lower-check.ll (original)
+++ llvm/trunk/test/Transforms/IRCE/only-lower-check.ll Mon May 23 17:16:45 2016
@@ -4,7 +4,7 @@
; CHECK-NEXT: InductiveRangeCheck:
; CHECK-NEXT: Kind: RANGE_CHECK_LOWER
; CHECK-NEXT: Offset: (-1 + %n) Scale: -1 Length: (null)
-; CHECK-NEXT: Branch: br i1 %abc, label %in.bounds, label %out.of.bounds
+; CHECK-NEXT: CheckUse: br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 Operand: 0
; CHECK-NEXT: irce: in function only_lower_check: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting>
define void @only_lower_check(i32 *%arr, i32 *%a_len_ptr, i32 %n) {
Modified: llvm/trunk/test/Transforms/IRCE/only-upper-check.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IRCE/only-upper-check.ll?rev=270500&r1=270499&r2=270500&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IRCE/only-upper-check.ll (original)
+++ llvm/trunk/test/Transforms/IRCE/only-upper-check.ll Mon May 23 17:16:45 2016
@@ -4,7 +4,7 @@
; CHECK-NEXT:InductiveRangeCheck:
; CHECK-NEXT: Kind: RANGE_CHECK_UPPER
; CHECK-NEXT: Offset: %offset Scale: 1 Length: %len = load i32, i32* %a_len_ptr, !range !0
-; CHECK-NEXT: Branch: br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
+; CHECK-NEXT: CheckUse: br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 Operand: 0
; CHECK-NEXT: irce: in function incrementing: constrained Loop at depth 1 containing: %loop<header><exiting>,%in.bounds<latch><exiting>
define void @incrementing(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) {
More information about the llvm-commits
mailing list