From 1acab00229576cdb8ba5972d3794dfcc76282c08 Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Mon, 18 Dec 2017 14:23:30 +0000 Subject: [PATCH] [LVI] Support for ashr in LVI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhance LVI to analyze the ‘ashr’ binary operation. This leverages the infrastructure in ConstantRange for the ashr operation. Patch by Surya Kumari Jangala! Differential Revision: https://reviews.llvm.org/D40886 llvm-svn: 320983 --- llvm/lib/Analysis/LazyValueInfo.cpp | 1 + .../LazyValueAnalysis/lvi-for-ashr.ll | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 llvm/test/Analysis/LazyValueAnalysis/lvi-for-ashr.ll diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 709d4f144bba..d7da669f6e79 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1002,6 +1002,7 @@ bool LazyValueInfoImpl::solveBlockValueBinaryOp(ValueLatticeElement &BBLV, case Instruction::UDiv: case Instruction::Shl: case Instruction::LShr: + case Instruction::AShr: case Instruction::And: case Instruction::Or: // continue into the code below diff --git a/llvm/test/Analysis/LazyValueAnalysis/lvi-for-ashr.ll b/llvm/test/Analysis/LazyValueAnalysis/lvi-for-ashr.ll new file mode 100644 index 000000000000..cdc27e4d0b3c --- /dev/null +++ b/llvm/test/Analysis/LazyValueAnalysis/lvi-for-ashr.ll @@ -0,0 +1,27 @@ +; RUN: opt -correlated-propagation -S %s | FileCheck %s +; CHECK-LABEL: @test-ashr +; CHECK: bb_then +; CHECK: %. = select i1 true, i32 3, i32 2 +define i32 @test-ashr(i32 %c) { +chk65: + %cmp = icmp sgt i32 %c, 65 + br i1 %cmp, label %return, label %chk0 + +chk0: + %cmp1 = icmp slt i32 %c, 0 + br i1 %cmp, label %return, label %bb_if + +bb_if: + %ashr.val = ashr exact i32 %c, 2 + %cmp2 = icmp sgt i32 %ashr.val, 15 + br i1 %cmp2, label %bb_then, label %return + +bb_then: + %cmp3 = icmp eq i32 %ashr.val, 16 + %. = select i1 %cmp3, i32 3, i32 2 + br label %return + +return: + %retval = phi i32 [0, %chk65], [1, %chk0], [%., %bb_then], [4, %bb_if] + ret i32 %retval +}