-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[AVR] Fix Avr indvar detection and strength reduction (missed optimization) #152028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c520636
68222e9
b568da0
38ca224
3355ccc
c32207d
6f220a0
c1f620a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===- AVRTargetTransformInfo.h - AVR specific TTI ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This file defines a TargetTransformInfoImplBase conforming object specific | ||
/// to the AVR target machine. It uses the target's detailed information to | ||
/// provide more precise answers to certain TTI queries, while letting the | ||
/// target independent and default TTI implementations handle the rest. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_AVR_AVRTARGETTRANSFORMINFO_H | ||
#define LLVM_LIB_TARGET_AVR_AVRTARGETTRANSFORMINFO_H | ||
|
||
#include "AVRSubtarget.h" | ||
#include "AVRTargetMachine.h" | ||
#include "llvm/Analysis/TargetTransformInfo.h" | ||
#include "llvm/CodeGen/BasicTTIImpl.h" | ||
#include "llvm/IR/Function.h" | ||
#include <optional> | ||
|
||
namespace llvm { | ||
benshi001 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class AVRTTIImpl final : public BasicTTIImplBase<AVRTTIImpl> { | ||
using BaseT = BasicTTIImplBase<AVRTTIImpl>; | ||
using TTI = TargetTransformInfo; | ||
|
||
friend BaseT; | ||
|
||
const AVRSubtarget *ST; | ||
const AVRTargetLowering *TLI; | ||
|
||
const AVRSubtarget *getST() const { return ST; } | ||
const AVRTargetLowering *getTLI() const { return TLI; } | ||
|
||
public: | ||
explicit AVRTTIImpl(const AVRTargetMachine *TM, const Function &F) | ||
: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)), | ||
TLI(ST->getTargetLowering()) {} | ||
|
||
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1, | ||
const TargetTransformInfo::LSRCost &C2) const override { | ||
if (C2.Insns == ~0u) | ||
Patryk27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
return 2 * C1.Insns + C1.AddRecCost + C1.SetupCost + C1.NumRegs < | ||
2 * C2.Insns + C2.AddRecCost + C2.SetupCost + C2.NumRegs; | ||
} | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_AVR_AVRTARGETTRANSFORMINFO_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc < %s -mtriple=avr-none -verify-machineinstrs | FileCheck %s | ||
|
||
declare dso_local void @foo(i16 noundef) addrspace(1) | ||
@ci = dso_local global [30 x i16] zeroinitializer, align 1 | ||
define void @loopreduce() { | ||
; CHECK-LABEL: loopreduce: | ||
; CHECK: ; %bb.0: ; %entry | ||
; CHECK-NEXT: push r14 | ||
; CHECK-NEXT: push r15 | ||
; CHECK-NEXT: push r16 | ||
; CHECK-NEXT: push r17 | ||
; CHECK-NEXT: ldi r26, lo8(ci) | ||
; CHECK-NEXT: ldi r27, hi8(ci) | ||
; CHECK-NEXT: ldi r16, lo8(ci+60) | ||
; CHECK-NEXT: ldi r17, hi8(ci+60) | ||
; CHECK-NEXT: .LBB0_1: ; %for.body | ||
; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1 | ||
; CHECK-NEXT: ld r24, X+ | ||
; CHECK-NEXT: ld r25, X+ | ||
; CHECK-NEXT: mov r14, r26 | ||
; CHECK-NEXT: mov r15, r27 | ||
; CHECK-NEXT: rcall foo | ||
; CHECK-NEXT: mov r26, r14 | ||
; CHECK-NEXT: mov r27, r15 | ||
; CHECK-NEXT: cp r26, r16 | ||
; CHECK-NEXT: cpc r27, r17 | ||
; CHECK-NEXT: brne .LBB0_1 | ||
; CHECK-NEXT: ; %bb.2: ; %for.cond.cleanup | ||
; CHECK-NEXT: pop r17 | ||
; CHECK-NEXT: pop r16 | ||
; CHECK-NEXT: pop r15 | ||
; CHECK-NEXT: pop r14 | ||
; CHECK-NEXT: ret | ||
entry: | ||
br label %for.body | ||
for.body: ; preds = %entry, %for.body | ||
%i.03 = phi i16 [ 0, %entry ], [ %inc, %for.body ] | ||
%arrayidx = getelementptr inbounds nuw [30 x i16], ptr @ci, i16 0, i16 %i.03 | ||
%0 = load i16, ptr %arrayidx, align 1 | ||
tail call addrspace(1) void @foo(i16 noundef %0) #3 | ||
%inc = add nuw nsw i16 %i.03, 1 | ||
%exitcond.not = icmp eq i16 %inc, 30 | ||
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body | ||
; Exit blocks | ||
for.cond.cleanup: ; preds = %for.body | ||
ret void | ||
} | ||
|
||
|
||
define void @induction() { | ||
; CHECK-LABEL: induction: | ||
; CHECK: ; %bb.0: ; %entry | ||
; CHECK-NEXT: push r12 | ||
; CHECK-NEXT: push r13 | ||
; CHECK-NEXT: push r14 | ||
; CHECK-NEXT: push r15 | ||
; CHECK-NEXT: push r17 | ||
; CHECK-NEXT: ldi r24, 8 | ||
; CHECK-NEXT: ldi r25, 0 | ||
; CHECK-NEXT: mov r14, r24 | ||
; CHECK-NEXT: mov r15, r25 | ||
; CHECK-NEXT: ldi r24, 1 | ||
; CHECK-NEXT: ldi r25, 0 | ||
; CHECK-NEXT: mov r12, r24 | ||
; CHECK-NEXT: mov r13, r25 | ||
; CHECK-NEXT: ldi r17, 3 | ||
; CHECK-NEXT: .LBB1_1: ; %for.body | ||
; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1 | ||
; CHECK-NEXT: mov r24, r12 | ||
; CHECK-NEXT: mov r25, r13 | ||
; CHECK-NEXT: rcall foo | ||
; CHECK-NEXT: mov r22, r14 | ||
; CHECK-NEXT: mov r23, r15 | ||
; CHECK-NEXT: mov r24, r22 | ||
; CHECK-NEXT: mov r25, r23 | ||
; CHECK-NEXT: rcall __mulhi3 | ||
; CHECK-NEXT: mov r30, r14 | ||
; CHECK-NEXT: mov r31, r15 | ||
; CHECK-NEXT: adiw r30, 1 | ||
; CHECK-NEXT: mov r14, r30 | ||
; CHECK-NEXT: mov r15, r31 | ||
; CHECK-NEXT: cpi r24, -24 | ||
; CHECK-NEXT: cpc r25, r17 | ||
; CHECK-NEXT: brlo .LBB1_1 | ||
; CHECK-NEXT: ; %bb.2: ; %for.cond.cleanup | ||
; CHECK-NEXT: pop r17 | ||
; CHECK-NEXT: pop r15 | ||
; CHECK-NEXT: pop r14 | ||
; CHECK-NEXT: pop r13 | ||
; CHECK-NEXT: pop r12 | ||
; CHECK-NEXT: ret | ||
entry: | ||
br label %for.body | ||
for.body: ; preds = %entry, %for.body | ||
%i.03 = phi i16 [ 7, %entry ], [ %inc, %for.body ] | ||
tail call addrspace(1) void @foo(i16 noundef 1) #2 | ||
%inc = add nuw nsw i16 %i.03, 1 | ||
%mul = mul nuw nsw i16 %inc, %inc | ||
%cmp = icmp samesign ult i16 %mul, 1000 | ||
br i1 %cmp, label %for.body, label %for.cond.cleanup | ||
for.cond.cleanup: ; preds = %for.body | ||
ret void | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,9 @@ while.end: ; preds = %while.body, %entry | |
|
||
define void @store8predec(ptr %x, i8 %y) { | ||
; CHECK-LABEL: store8predec: | ||
; CHECK: st -{{[XYZ]}}, {{.*}} | ||
; TODO: st -{{[XYZ]}}, {{.*}} | ||
; CHECK: sbiw {{..*}}, 1 | ||
; CHECK: st {{[XYZ]}}, {{.*}} | ||
entry: | ||
%tobool3 = icmp eq i8 %y, 0 | ||
br i1 %tobool3, label %while.end, label %while.body | ||
|
@@ -112,8 +114,11 @@ while.end: ; preds = %while.body, %entry | |
|
||
define void @store16predec(ptr %x, i16 %y) { | ||
; CHECK-LABEL: store16predec: | ||
; CHECK: st -{{[XYZ]}}, {{.*}} | ||
; CHECK: st -{{[XYZ]}}, {{.*}} | ||
; TODO: st -{{[XYZ]}}, {{.*}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides changing to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems there are still a couple of I'd be up for committing the actually-used registers instead of playing around with the interpolation/expression notation ( |
||
; TODO: st -{{[XYZ]}}, {{.*}} | ||
; CHECK: sbiw {{..*}}, 2 | ||
; CHECK: std {{[XYZ]}}+1, {{.*}} | ||
; CHECK: st {{[XYZ]}}, {{.*}} | ||
entry: | ||
%tobool3 = icmp eq i16 %y, 0 | ||
br i1 %tobool3, label %while.end, label %while.body | ||
|
Uh oh!
There was an error while loading. Please reload this page.