From cd5029d00108df094b1ed225fb81f4eeece580a9 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Mon, 9 Mar 2015 21:43:43 +0000 Subject: [SCEV] Unify getUnsignedRange and getSignedRange Summary: This removes some duplicated code, and also helps optimization: e.g. in the test case added, `%idx ULT 128` in `@x` is not currently optimized to `true` by `-indvars` but will be, after this change. The only functional change in ths commit is that for add recurrences, ScalarEvolution::getRange will be more aggressive -- computing the unsigned (resp. signed) range for a SCEVAddRecExpr will now look at the NSW (resp. NUW) bits and check for signed (resp. unsigned) overflow. This can be a strict improvement in some cases (such as the attached test case), and should be no worse in other cases. Reviewers: atrick, nlewycky Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8142 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231709 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Analysis/ScalarEvolution/range-signedness.ll | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/Analysis/ScalarEvolution/range-signedness.ll (limited to 'test') diff --git a/test/Analysis/ScalarEvolution/range-signedness.ll b/test/Analysis/ScalarEvolution/range-signedness.ll new file mode 100644 index 00000000000..d04fc9eb56b --- /dev/null +++ b/test/Analysis/ScalarEvolution/range-signedness.ll @@ -0,0 +1,39 @@ +; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s + +define void @x(i1* %cond) { +; CHECK-LABEL: Classifying expressions for: @x + entry: + br label %loop + + loop: + %idx = phi i8 [ 0, %entry ], [ %idx.inc, %loop ] +; CHECK: %idx = phi i8 [ 0, %entry ], [ %idx.inc, %loop ] +; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,-128) S: [0,-128) + + %idx.inc = add nsw i8 %idx, 1 + + %c = load volatile i1, i1* %cond + br i1 %c, label %loop, label %exit + + exit: + ret void +} + +define void @y(i8* %addr) { +; CHECK-LABEL: Classifying expressions for: @y + entry: + br label %loop + + loop: + %idx = phi i8 [-5, %entry ], [ %idx.inc, %loop ] +; CHECK: %idx = phi i8 [ -5, %entry ], [ %idx.inc, %loop ] +; CHECK-NEXT: --> {-5,+,1}<%loop> U: [-5,6) S: [-5,6) + + %idx.inc = add i8 %idx, 1 + + %continue = icmp slt i8 %idx.inc, 6 + br i1 %continue, label %loop, label %exit + + exit: + ret void +} -- cgit v1.2.3