[PATCH] Allow InstCombiner to eliminate truncates even if it will require inserting additional instructions

Igor Laevsky igor at azulsystems.com
Tue Jun 30 09:11:17 PDT 2015


REPOSITORY
  rL LLVM

================
Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:225
@@ +224,3 @@
+    // This is not a recognized instruction. We need an explicit cast here.
+    // Currently we can reach this only when truncating expression type.
+    assert(CastInst::castIsValid(Instruction::Trunc, I, Ty) &&
----------------
sanjoy wrote:
> It isn't clear what 'truncating expression type' means here.  Can you turn this into an assert?
There is an assertion for this on the next line. It checks that we can reach destination type by applying truncate instruction.

================
Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:371
@@ -350,3 +370,3 @@
   // require duplicating the instruction in general, which isn't profitable.
   if (!I->hasOneUse()) return false;
 
----------------
sanjoy wrote:
> Given that we're now tracking a generalized cost, does it make sense to remove this and have
> 
> ```
> case Inst::Add:
>   bool Left = EstimateCostFor(LHS);
>   bool Right = EstimateCostFor(LHS);
>   if (Left && Right) {
>     if (!I->hasOneUse())
>       Cost++;  // new add instruction  (or may be +=2 because of code duplication)
>     return true;
>   } else return false;
> ```
> 
> (Not necessarily in this change, but in a later change?)
It is possible. However I would be careful about such transform since it increases register pressure, some targets might not respond to this change positively.

http://reviews.llvm.org/D10571

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list