From 73f565e7546f63900738cd31a2f956444e7bb544 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Wed, 19 Jan 2011 15:56:12 +0000 Subject: [PATCH] Add a missing SCEV simplification sext(zext x) --> zext x. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123832 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ScalarEvolution.cpp | 4 ++++ test/Analysis/ScalarEvolution/fold.ll | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/Analysis/ScalarEvolution/fold.ll diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index b3df9261195..ce041884909 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -994,6 +994,10 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, if (const SCEVSignExtendExpr *SS = dyn_cast(Op)) return getSignExtendExpr(SS->getOperand(), Ty); + // sext(zext(x)) --> zext(x) + if (const SCEVZeroExtendExpr *SZ = dyn_cast(Op)) + return getZeroExtendExpr(SZ->getOperand(), Ty); + // Before doing any expensive analysis, check to see if we've already // computed a SCEV for this Op and Ty. FoldingSetNodeID ID; diff --git a/test/Analysis/ScalarEvolution/fold.ll b/test/Analysis/ScalarEvolution/fold.ll new file mode 100644 index 00000000000..202ddd4169a --- /dev/null +++ b/test/Analysis/ScalarEvolution/fold.ll @@ -0,0 +1,8 @@ +; RUN: opt -analyze -scalar-evolution %s -S | FileCheck %s + +define i16 @test(i8 %x) { + %A = zext i8 %x to i12 + %B = sext i12 %A to i16 +; CHECK: zext i8 %x to i16 + ret i16 %B +}