[PATCH] D47928: [SimplifyIndVars] Eliminate redundant truncs

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 7 23:08:04 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: reames, etherzhhb, greened, sanjoy.

This patch adds logic to deal with the following constructions:

  %iv = phi i64 ...
  %trunc = trunc i64 %iv to i32
  %cmp = icmp <pred> i32 %trunc, %invariant

Replacing it with

  %iv = phi i64 ...
  %cmp = icmp <pred> i64 %iv, sext/zext(%invariant)

In case if it is legal. Specifically, if `%iv` has signed comparison users, it is
required that `sext(trunc(%iv)) == %iv`, and if it has unsigned comparison
uses then we require `zext(trunc(%iv)) == %iv`. The current implementation
bails if `%trunc` has other uses than `icmp`, but in theory we can handle more
cases here (e.g. if the user of trunc is bitcast).


https://reviews.llvm.org/D47928

Files:
  lib/Transforms/Utils/SimplifyIndVar.cpp
  test/Transforms/IndVarSimplify/eliminate-trunc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47928.150450.patch
Type: text/x-patch
Size: 17564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180608/c26ba774/attachment.bin>


More information about the llvm-commits mailing list