Lines Matching +full:bit +full:- +full:shift
1 //===- AVRShift.cpp - Shift Expansion Pass --------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Expand non-8-bit and non-16-bit shift instructions (shl, lshr, ashr) to
11 /// inline loops, just like avr-gcc. This must be done in IR because otherwise
12 /// the type legalizer will turn 32-bit shifts into (non-existing) library calls
15 //===----------------------------------------------------------------------===//
33 StringRef getPassName() const override { return "AVR Shift Expansion"; } in getPassName()
43 INITIALIZE_PASS(AVRShiftExpand, "avr-shift-expand", "AVR Shift Expansion",
53 // Only expand shift instructions (shl, lshr, ashr). in runOnFunction()
56 // Only expand non-8-bit and non-16-bit shifts, since those are expanded in runOnFunction()
60 // Only expand when the shift amount is not known. in runOnFunction()
61 // Known shift amounts are (currently) better expanded inline. in runOnFunction()
73 // Return whether this function expanded any shift instructions. in runOnFunction()
78 auto &Ctx = BI->getContext(); in expand()
80 Type *InputTy = cast<Instruction>(BI)->getType(); in expand()
84 // Split the current basic block at the point of the existing shift in expand()
86 BasicBlock *BB = BI->getParent(); in expand()
87 Function *F = BB->getParent(); in expand()
88 BasicBlock *EndBB = BB->splitBasicBlock(BI, "shift.done"); in expand()
89 BasicBlock *LoopBB = BasicBlock::Create(Ctx, "shift.loop", F, EndBB); in expand()
91 // Truncate the shift amount to i8, which is trivially lowered to a single in expand()
93 Builder.SetInsertPoint(&BB->back()); in expand()
94 Value *ShiftAmount = Builder.CreateTrunc(BI->getOperand(1), Int8Ty); in expand()
100 BB->back().eraseFromParent(); in expand()
105 ShiftAmountPHI->addIncoming(ShiftAmount, BB); in expand()
107 ValuePHI->addIncoming(BI->getOperand(0), BB); in expand()
109 // Subtract the shift amount by one, as we're shifting one this loop in expand()
113 ShiftAmountPHI->addIncoming(ShiftAmountSub, LoopBB); in expand()
115 // Emit the actual shift instruction. The difference is that this shift in expand()
116 // instruction has a constant shift amount, which can be emitted inline in expand()
119 switch (BI->getOpcode()) { in expand()
130 llvm_unreachable("asked to expand an instruction that is not a shift"); in expand()
132 ValuePHI->addIncoming(ValueShifted, LoopBB); in expand()
134 // Branch to either the loop again (if there is more to shift) or to the in expand()
143 Result->addIncoming(BI->getOperand(0), BB); in expand()
144 Result->addIncoming(ValueShifted, LoopBB); in expand()
146 // Replace the original shift instruction. in expand()
147 BI->replaceAllUsesWith(Result); in expand()
148 BI->eraseFromParent(); in expand()