Skip to content

Commit b308eec

Browse files
committed
Prefer 8 bits for AVR
Issue 153156
1 parent abf5480 commit b308eec

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,9 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) {
17661766
// This handles the case only when the Cmp instruction is guarding a recursive
17671767
// call that will cause the Cmp to fail/succeed for the recursive call.
17681768
bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
1769+
// FIXME Regression on AVR: github.com/llvm/llvm-project/issues/153156
1770+
if (!DL.isLegalInteger(32))
1771+
return false;
17691772
// Bail out if LHS is not a function argument or RHS is NOT const:
17701773
if (!isa<Argument>(Cmp.getOperand(0)) || !isa<Constant>(Cmp.getOperand(1)))
17711774
return false;

llvm/lib/Target/AVR/AVRTargetTransformInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class AVRTTIImpl final : public BasicTTIImplBase<AVRTTIImpl> {
4444

4545
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
4646
const TargetTransformInfo::LSRCost &C2) const override;
47+
48+
TypeSize
49+
getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const override {
50+
// default is 32, so change it to 16
51+
return TypeSize::getFixed(16);
52+
}
4753
};
4854

4955
} // end namespace llvm

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,12 +1632,17 @@ Instruction *InstCombinerImpl::visitPHINode(PHINode &PN) {
16321632
return replaceInstUsesWith(PN, &IdenticalPN);
16331633
}
16341634

1635-
// If this is an integer PHI and we know that it has an illegal type, see if
1635+
// For 8/16 bit CPUs prefer 8 bit registers
1636+
bool preferByteRegister = !DL.isLegalInteger(32);
1637+
1638+
// If this is an integer PHI and we know that it has an illegal type,
1639+
// (or 16 bit on 8/16 bit CPUs), see if
16361640
// it is only used by trunc or trunc(lshr) operations. If so, we split the
16371641
// PHI into the various pieces being extracted. This sort of thing is
16381642
// introduced when SROA promotes an aggregate to a single large integer type.
16391643
if (PN.getType()->isIntegerTy() &&
1640-
!DL.isLegalInteger(PN.getType()->getPrimitiveSizeInBits()))
1644+
((!DL.isLegalInteger(PN.getType()->getPrimitiveSizeInBits())) ||
1645+
(preferByteRegister && PN.getType()->getPrimitiveSizeInBits() == 16)))
16411646
if (Instruction *Res = SliceUpIllegalIntegerPHI(PN))
16421647
return Res;
16431648

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ bool InstCombinerImpl::shouldChangeType(unsigned FromWidth,
311311
bool FromLegal = FromWidth == 1 || DL.isLegalInteger(FromWidth);
312312
bool ToLegal = ToWidth == 1 || DL.isLegalInteger(ToWidth);
313313

314+
// For 8/16 bit CPUs prefer 8 bit.
315+
if (!DL.isLegalInteger(32) && ToWidth == 16)
316+
ToLegal = false;
317+
314318
// Convert to desirable widths even if they are not legal types.
315319
// Only shrink types, to prevent infinite loops.
316320
if (ToWidth < FromWidth && isDesirableIntType(ToWidth))

0 commit comments

Comments
 (0)