[PATCH] D12012: [InstCombineCasts] Insert truncates when evaluating expression in different type
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 09:48:49 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.
Support insertion of truncates in `EvaluateInDifferentType`. Actual usage of this code would be exposed in a follow up change.
Repository:
rL LLVM
http://reviews.llvm.org/D12012
Files:
lib/Transforms/InstCombine/InstCombineCasts.cpp
Index: lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -221,9 +221,25 @@
}
default:
// TODO: Can handle more cases here.
- llvm_unreachable("Unreachable!");
+ // This is not a recognized instruction. We need an explicit cast here.
+ // Currently we support this only when truncating expression type.
+ assert(CastInst::castIsValid(Instruction::Trunc, I, Ty) &&
+ "can not insert explicit cast");
+ assert(I->hasOneUse() &&
+ "can not truncate branching expression trees");
+
+ // Create truncate from "I" type to the Ty
+ Instruction *Trunc = CastInst::CreateTruncOrBitCast(I, Ty);
+ Trunc->setName(I->getName() + ".truncated");
+
+ // Insert new truncate after "I"
+ Instruction *NextI = I->getNextNode();
+ assert(NextI != I->getParent()->end() &&
+ "can not insert explicit truncate");
+ return InsertNewInstBefore(Trunc, *NextI);
}
+ assert(Res && "failed to evaluate instruction in different type");
Res->takeName(I);
return InsertNewInstWith(Res, *I);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12012.32071.patch
Type: text/x-patch
Size: 1225 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150813/a0a85769/attachment.bin>
More information about the llvm-commits
mailing list