Lines Matching defs:SExt
14 // d = sext i32 a to i64
18 // f = sext i32 b to i64
24 // Moreover, the current heuristic is simple: it does not create new sext
25 // operations, i.e., it gives up when a sext would have forked (e.g., if
85 // sext instructions.
107 /// Check if it is profitable to move a sext through this instruction.
110 /// - Inst has only one operand that will require a sext operation (we do
111 /// do not create new sext operation).
114 /// Check if it is possible and legal to move a sext through this
118 /// - Other sext operation.
122 /// Move sext operations through safe to sext instructions.
125 /// Is this sext should be considered for code motion.
126 /// We look for sext with ConsideredSExtType and uses in at least one
128 bool shouldConsiderSExt(const Instruction *SExt) const;
130 /// Collect all interesting sext operations, i.e., the ones with the right
132 /// More precisely, a sext instruction is considered as interesting if it
134 /// sext instruction that sign extended the same initial value.
166 // sext(trunc(sext)) --> sext
181 // If the type of the sext is the same as the considered one, this sext
199 // If both operands are not constant, a new sext will be created here.
201 // Therefore we don't allow to increase the number of sext even if it may
216 AArch64AddressTypePromotion::shouldConsiderSExt(const Instruction *SExt) const {
217 if (SExt->getType() != ConsideredSExtType)
220 for (const User *U : SExt->users()) {
229 // - SExtInsts contains all the sext instructions that are used directly in
232 // - For each sext operation in SExtInsts:
233 // Let var be the operand of sext.
235 // (see canGetThrough) to move sext through var's definition:
237 // * fold var into sext uses.
238 // * move sext above var's definition.
239 // * update sext operand to use the operand of var that should be sign
244 // b = sext i32 a to i64 <- is it legal/safe/profitable to get through 'a'
248 // b = sext i32 c to i64
262 Instruction *SExt = SExtInsts.pop_back_val();
264 DEBUG(dbgs() << "Consider:\n" << *SExt << '\n');
266 // If this SExt has already been merged continue.
267 if (SExt->use_empty() && ToRemove.count(SExt)) {
273 while (auto *Inst = dyn_cast<Instruction>(SExt->getOperand(0))) {
277 // or not safe to SExt.
285 DEBUG(dbgs() << "SExt or trunc, mark it as to remove\n");
287 // assertion on the type as all involved sext operation may have not
292 assert(User && "User of sext is not an Instruction!");
293 User->setOperand(U.getOperandNo(), SExt);
296 SExt->setOperand(0, Inst->getOperand(0));
297 SExt->moveBefore(Inst);
303 // 2. Replace the uses of SExt by Inst.
307 Inst->mutateType(SExt->getType());
309 SExt->replaceAllUsesWith(Inst);
311 Instruction *SExtForOpnd = SExt;
313 DEBUG(dbgs() << "Propagate SExt to operands\n");
317 if (Inst->getOperand(OpIdx)->getType() == SExt->getType() ||
326 Inst->setOperand(OpIdx, ConstantInt::getSigned(SExt->getType(),
333 Inst->setOperand(OpIdx, UndefValue::get(SExt->getType()));
347 // If more sext are required, new instructions will have to be created.
350 if (SExtForOpnd == SExt) {
352 ToRemove.insert(SExt);
360 if (!ToRemove.count(SExt) &&
361 SExt->getType() == SExt->getOperand(0)->getType()) {
364 SExt->replaceAllUsesWith(SExt->getOperand(0));
365 ToRemove.insert(SExt);
367 ValToSExtendedUses[SExt->getOperand(0)].push_back(SExt);
425 Instruction *SExt = &II;
427 // Collect all sext operation per type.
428 if (!isa<SExtInst>(SExt) || !shouldConsiderSExt(SExt))
431 DEBUG(dbgs() << "Found:\n" << (*SExt) << '\n');
434 // 1. SExt is used in a getelementptr with more than 2 operand =>
436 // 2. The beginning of the SExt chain is SExt several time. =>
441 for (const User *U : SExt->users()) {
453 Instruction *Inst = SExt;
469 SExtInsts.push_back(SExt);
477 SeenChains[Last] = SExt;