llvm-project/llvm/lib/Transforms/InstCombine
David Bolvansky af1b3185f5 [InstCombine] Fold select (icmp sgt x, -1), lshr (X, Y), ashr (X, Y) to ashr (X, Y))
Summary:
(select (icmp sgt x, -1), lshr (X, Y), ashr (X, Y)) -> ashr (X, Y))
(select (icmp slt x, 1), ashr (X, Y), lshr (X, Y)) -> ashr (X, Y))

Fixes PR41173

Alive proof by @lebedev.ri (thanks)
Name: PR41173
  %cmp = icmp slt i32 %x, 1
  %shr = lshr i32 %x, %y
  %shr1 = ashr i32 %x, %y
  %retval.0 = select i1 %cmp, i32 %shr1, i32 %shr
  =>
  %retval.0 = ashr i32 %x, %y

Optimization: PR41173
Done: 1
Optimization is correct!

Reviewers: lebedev.ri, spatel

Reviewed By: lebedev.ri

Subscribers: nikic, craig.topper, llvm-commits, lebedev.ri

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64285

llvm-svn: 365893
2019-07-12 11:31:16 +00:00
..
CMakeLists.txt [InstCombine] Optimize `atomicrmw <op>, 0` into `load atomic` when possible 2019-02-07 21:27:23 +00:00
InstCombineAddSub.cpp [InstCombine] Y - ~X --> X + Y + 1 fold (PR42457) 2019-07-03 09:41:50 +00:00
InstCombineAndOrXor.cpp [InstCombine] squash is-not-power-of-2 using ctpop 2019-06-24 22:35:26 +00:00
InstCombineAtomicRMW.cpp [InstCombine] Extend saturating idempotent atomicrmw transform to FP 2019-03-01 19:50:36 +00:00
InstCombineCalls.cpp OpaquePtr: add Type parameter to Loads analysis API. 2019-07-09 11:35:35 +00:00
InstCombineCasts.cpp [InstCombine] Update fptrunc (fneg x)) -> (fneg (fptrunc x) for unary FNeg 2019-06-11 15:45:41 +00:00
InstCombineCompares.cpp [PatternMatch] Generalize m_SpecificInt_ULT() to take ICmpInst::Predicate 2019-07-10 16:07:35 +00:00
InstCombineInternal.h [InstCombine] Refactor OptimizeOverflowCheck; NFCI 2019-05-26 11:43:37 +00:00
InstCombineLoadStoreAlloca.cpp OpaquePtr: add Type parameter to Loads analysis API. 2019-07-09 11:35:35 +00:00
InstCombineMulDivRem.cpp [InstCombine] don't move FP negation out of a constant expression 2019-07-11 13:44:29 +00:00
InstCombinePHI.cpp [InstCombine] SliceUpIllegalIntegerPHI - bail on out of range shifts 2019-06-24 13:13:36 +00:00
InstCombineSelect.cpp [InstCombine] Fold select (icmp sgt x, -1), lshr (X, Y), ashr (X, Y) to ashr (X, Y)) 2019-07-12 11:31:16 +00:00
InstCombineShifts.cpp [PatternMatch] Generalize m_SpecificInt_ULT() to take ICmpInst::Predicate 2019-07-10 16:07:35 +00:00
InstCombineSimplifyDemanded.cpp [IntrinsicEmitter] Extend argument overloading with forward references. 2019-06-13 08:19:33 +00:00
InstCombineTables.td InstCombine/AMDGPU: Add dimension-aware image intrinsics to SimplifyDemanded 2018-06-21 13:37:31 +00:00
InstCombineVectorOps.cpp [InstCombine] fold insertelement into splat of same scalar 2019-07-08 19:48:52 +00:00
InstructionCombining.cpp InstCombine: Preserve nuw when reassociating nuw ops [3/3] 2019-06-24 21:37:03 +00:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00