[PATCH] D12013: [InstCombineCasts] Add cost model to decide which truncates are worth removing

Igor Laevsky via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 09:56:37 PDT 2015


igor-laevsky created this revision.
igor-laevsky added a reviewer: majnemer.
igor-laevsky added a subscriber: llvm-commits.
igor-laevsky set the repository for this revision to rL LLVM.

Currently InstCombiner will eliminate truncate only when entire expression tree can be evaluated in a narrower type without adding additional instructions.

However there are some cases when it is profitable to evaluate expression in a narrower type, even if it will require adding additional instructions. (See test case in the patch)

In this patch I split "CanEvaluateTruncated" function into two: "EstimateCostForTruncatedEvaluation" and "IsProfitableToEvaluateTruncated". First one is basically an old "CanEvaluateTruncated", but it also calculates cost for truncating expression tree. Second function calls "EstimateCostForTruncatedEvaluation" and compares cost of the truncation with constant threshold.

Currently cost model is very simple - we want to truncate expression tree only if we will remove more instructions than we will add. 


Repository:
  rL LLVM

http://reviews.llvm.org/D12013

Files:
  lib/Transforms/InstCombine/InstCombineCasts.cpp
  lib/Transforms/InstCombine/InstCombineInternal.h
  test/Transforms/InstCombine/trunc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12013.32072.patch
Type: text/x-patch
Size: 11260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150813/21fdb918/attachment.bin>


More information about the llvm-commits mailing list