mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-05 14:52:02 +00:00
[Hexagon] Bit-based instruction simplification
Analyze bit patterns of operands and values of instructions to perform various simplifications, dead/redundant code elimination, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250868 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
84aa3b5def
commit
c75a253689
@ -14,6 +14,7 @@ add_public_tablegen_target(HexagonCommonTableGen)
|
|||||||
add_llvm_target(HexagonCodeGen
|
add_llvm_target(HexagonCodeGen
|
||||||
BitTracker.cpp
|
BitTracker.cpp
|
||||||
HexagonAsmPrinter.cpp
|
HexagonAsmPrinter.cpp
|
||||||
|
HexagonBitSimplify.cpp
|
||||||
HexagonBitTracker.cpp
|
HexagonBitTracker.cpp
|
||||||
HexagonCFGOptimizer.cpp
|
HexagonCFGOptimizer.cpp
|
||||||
HexagonCommonGEP.cpp
|
HexagonCommonGEP.cpp
|
||||||
|
2778
lib/Target/Hexagon/HexagonBitSimplify.cpp
Normal file
2778
lib/Target/Hexagon/HexagonBitSimplify.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -62,6 +62,12 @@ static cl::opt<bool> EnableGenPred("hexagon-gen-pred", cl::init(true),
|
|||||||
static cl::opt<bool> DisableHSDR("disable-hsdr", cl::init(false), cl::Hidden,
|
static cl::opt<bool> DisableHSDR("disable-hsdr", cl::init(false), cl::Hidden,
|
||||||
cl::desc("Disable splitting double registers"));
|
cl::desc("Disable splitting double registers"));
|
||||||
|
|
||||||
|
static cl::opt<bool> EnableBitSimplify("hexagon-bit", cl::init(true),
|
||||||
|
cl::Hidden, cl::desc("Bit simplification"));
|
||||||
|
|
||||||
|
static cl::opt<bool> EnableLoopResched("hexagon-loop-resched", cl::init(true),
|
||||||
|
cl::Hidden, cl::desc("Loop rescheduling"));
|
||||||
|
|
||||||
/// HexagonTargetMachineModule - Note that this is used on hosts that
|
/// HexagonTargetMachineModule - Note that this is used on hosts that
|
||||||
/// cannot link in a library unless there are references into the
|
/// cannot link in a library unless there are references into the
|
||||||
/// library. In particular, it seems that it is not possible to get
|
/// library. In particular, it seems that it is not possible to get
|
||||||
@ -84,6 +90,7 @@ SchedCustomRegistry("hexagon", "Run Hexagon's custom scheduler",
|
|||||||
createVLIWMachineSched);
|
createVLIWMachineSched);
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
FunctionPass *createHexagonBitSimplify();
|
||||||
FunctionPass *createHexagonCallFrameInformation();
|
FunctionPass *createHexagonCallFrameInformation();
|
||||||
FunctionPass *createHexagonCFGOptimizer();
|
FunctionPass *createHexagonCFGOptimizer();
|
||||||
FunctionPass *createHexagonCommonGEP();
|
FunctionPass *createHexagonCommonGEP();
|
||||||
@ -99,6 +106,7 @@ namespace llvm {
|
|||||||
FunctionPass *createHexagonHardwareLoops();
|
FunctionPass *createHexagonHardwareLoops();
|
||||||
FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM,
|
FunctionPass *createHexagonISelDag(HexagonTargetMachine &TM,
|
||||||
CodeGenOpt::Level OptLevel);
|
CodeGenOpt::Level OptLevel);
|
||||||
|
FunctionPass *createHexagonLoopRescheduling();
|
||||||
FunctionPass *createHexagonNewValueJump();
|
FunctionPass *createHexagonNewValueJump();
|
||||||
FunctionPass *createHexagonOptimizeSZextends();
|
FunctionPass *createHexagonOptimizeSZextends();
|
||||||
FunctionPass *createHexagonPacketizer();
|
FunctionPass *createHexagonPacketizer();
|
||||||
@ -223,9 +231,15 @@ bool HexagonPassConfig::addInstSelector() {
|
|||||||
// Create logical operations on predicate registers.
|
// Create logical operations on predicate registers.
|
||||||
if (EnableGenPred)
|
if (EnableGenPred)
|
||||||
addPass(createHexagonGenPredicate(), false);
|
addPass(createHexagonGenPredicate(), false);
|
||||||
|
// Rotate loops to expose bit-simplification opportunities.
|
||||||
|
if (EnableLoopResched)
|
||||||
|
addPass(createHexagonLoopRescheduling(), false);
|
||||||
// Split double registers.
|
// Split double registers.
|
||||||
if (!DisableHSDR)
|
if (!DisableHSDR)
|
||||||
addPass(createHexagonSplitDoubleRegs());
|
addPass(createHexagonSplitDoubleRegs());
|
||||||
|
// Bit simplification.
|
||||||
|
if (EnableBitSimplify)
|
||||||
|
addPass(createHexagonBitSimplify(), false);
|
||||||
addPass(createHexagonPeephole());
|
addPass(createHexagonPeephole());
|
||||||
printAndVerify("After hexagon peephole pass");
|
printAndVerify("After hexagon peephole pass");
|
||||||
if (EnableGenInsert)
|
if (EnableGenInsert)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: llc -march=hexagon -disable-hsdr -hexagon-expand-condsets=0 < %s | FileCheck %s
|
; RUN: llc -march=hexagon -disable-hsdr -hexagon-expand-condsets=0 -hexagon-bit=0 < %s | FileCheck %s
|
||||||
|
|
||||||
; CHECK: r{{[0-9]+:[0-9]+}} = #1
|
; CHECK: r{{[0-9]+:[0-9]+}} = #1
|
||||||
; CHECK: r{{[0-9]+:[0-9]+}} = #0
|
; CHECK: r{{[0-9]+:[0-9]+}} = #0
|
||||||
|
53
test/CodeGen/Hexagon/bit-eval.ll
Normal file
53
test/CodeGen/Hexagon/bit-eval.ll
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
; RUN: llc < %s | FileCheck %s
|
||||||
|
|
||||||
|
target datalayout = "e-m:e-p:32:32-i1:32-i64:64-a:0-v32:32-n16:32"
|
||||||
|
target triple = "hexagon"
|
||||||
|
|
||||||
|
; CHECK-LABEL: test1:
|
||||||
|
; CHECK: r0 = ##1073741824
|
||||||
|
define i32 @test1() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = tail call i32 @llvm.hexagon.S2.asr.i.r.rnd(i32 2147483647, i32 0)
|
||||||
|
ret i32 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: test2:
|
||||||
|
; CHECK: r0 = ##1073741824
|
||||||
|
define i32 @test2() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = tail call i32 @llvm.hexagon.S2.asr.i.r.rnd.goodsyntax(i32 2147483647, i32 1)
|
||||||
|
ret i32 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: test3:
|
||||||
|
; CHECK: r1:0 = #1
|
||||||
|
define i64 @test3() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = tail call i64 @llvm.hexagon.S4.extractp(i64 -1, i32 63, i32 63)
|
||||||
|
ret i64 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: test4:
|
||||||
|
; CHECK: r0 = #1
|
||||||
|
define i32 @test4() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = tail call i32 @llvm.hexagon.S4.extract(i32 -1, i32 31, i32 31)
|
||||||
|
ret i32 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: test5:
|
||||||
|
; CHECK: r0 = ##-1073741569
|
||||||
|
define i32 @test5() #0 {
|
||||||
|
entry:
|
||||||
|
%0 = tail call i32 @llvm.hexagon.S4.subi.lsr.ri(i32 255, i32 -2147483648, i32 1)
|
||||||
|
ret i32 %0
|
||||||
|
}
|
||||||
|
|
||||||
|
declare i32 @llvm.hexagon.S2.asr.i.r.rnd(i32, i32) #0
|
||||||
|
declare i32 @llvm.hexagon.S2.asr.i.r.rnd.goodsyntax(i32, i32) #0
|
||||||
|
declare i64 @llvm.hexagon.S4.extractp(i64, i32, i32) #0
|
||||||
|
declare i32 @llvm.hexagon.S4.extract(i32, i32, i32) #0
|
||||||
|
declare i32 @llvm.hexagon.S4.subi.lsr.ri(i32, i32, i32) #0
|
||||||
|
|
||||||
|
attributes #0 = { nounwind readnone }
|
||||||
|
|
80
test/CodeGen/Hexagon/bit-loop.ll
Normal file
80
test/CodeGen/Hexagon/bit-loop.ll
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
; RUN: llc < %s | FileCheck %s
|
||||||
|
; CHECK-DAG: memh(r{{[0-9]+}}+#0) = r{{[0-9]+}}
|
||||||
|
; CHECK-DAG: memh(r{{[0-9]+}}+#2) = r{{[0-9]+}}.h
|
||||||
|
; CHECK-DAG: memh(r{{[0-9]+}}+#4) = r{{[0-9]+}}
|
||||||
|
; CHECK-DAG: memh(r{{[0-9]+}}+#6) = r{{[0-9]+}}.h
|
||||||
|
|
||||||
|
target datalayout = "e-m:e-p:32:32-i1:32-i64:64-a:0-v32:32-n16:32"
|
||||||
|
target triple = "hexagon"
|
||||||
|
|
||||||
|
; Function Attrs: nounwind
|
||||||
|
define void @foo(i64* nocapture readonly %r64, i16 zeroext %n, i16 zeroext %s, i64* nocapture %p64) #0 {
|
||||||
|
entry:
|
||||||
|
%conv = zext i16 %n to i32
|
||||||
|
%cmp = icmp eq i16 %n, 0
|
||||||
|
br i1 %cmp, label %for.end, label %for.body.preheader
|
||||||
|
|
||||||
|
for.body.preheader: ; preds = %entry
|
||||||
|
%0 = load i64, i64* %r64, align 8, !tbaa !1
|
||||||
|
%v.sroa.0.0.extract.trunc = trunc i64 %0 to i16
|
||||||
|
%v.sroa.4.0.extract.shift = lshr i64 %0, 16
|
||||||
|
%v.sroa.4.0.extract.trunc = trunc i64 %v.sroa.4.0.extract.shift to i16
|
||||||
|
%v.sroa.5.0.extract.shift = lshr i64 %0, 32
|
||||||
|
%v.sroa.5.0.extract.trunc = trunc i64 %v.sroa.5.0.extract.shift to i16
|
||||||
|
%v.sroa.6.0.extract.shift = lshr i64 %0, 48
|
||||||
|
%v.sroa.6.0.extract.trunc = trunc i64 %v.sroa.6.0.extract.shift to i16
|
||||||
|
%1 = bitcast i64* %p64 to i16*
|
||||||
|
%conv2 = zext i16 %s to i32
|
||||||
|
%add.ptr = getelementptr inbounds i16, i16* %1, i32 %conv2
|
||||||
|
%add.ptr.sum = add nuw nsw i32 %conv2, 1
|
||||||
|
%add.ptr3 = getelementptr inbounds i16, i16* %1, i32 %add.ptr.sum
|
||||||
|
%add.ptr.sum50 = add nuw nsw i32 %conv2, 2
|
||||||
|
%add.ptr4 = getelementptr inbounds i16, i16* %1, i32 %add.ptr.sum50
|
||||||
|
%add.ptr.sum51 = add nuw nsw i32 %conv2, 3
|
||||||
|
%add.ptr5 = getelementptr inbounds i16, i16* %1, i32 %add.ptr.sum51
|
||||||
|
br label %for.body
|
||||||
|
|
||||||
|
for.body: ; preds = %for.body.preheader, %for.body
|
||||||
|
%add.ptr11.phi = phi i16* [ %add.ptr11.inc, %for.body ], [ %add.ptr, %for.body.preheader ]
|
||||||
|
%add.ptr16.phi = phi i16* [ %add.ptr16.inc, %for.body ], [ %add.ptr3, %for.body.preheader ]
|
||||||
|
%add.ptr21.phi = phi i16* [ %add.ptr21.inc, %for.body ], [ %add.ptr4, %for.body.preheader ]
|
||||||
|
%add.ptr26.phi = phi i16* [ %add.ptr26.inc, %for.body ], [ %add.ptr5, %for.body.preheader ]
|
||||||
|
%i.058.pmt = phi i32 [ %inc.pmt, %for.body ], [ 0, %for.body.preheader ]
|
||||||
|
%v.sroa.0.157 = phi i16 [ %v.sroa.0.0.extract.trunc34, %for.body ], [ %v.sroa.0.0.extract.trunc, %for.body.preheader ]
|
||||||
|
%v.sroa.4.156 = phi i16 [ %v.sroa.4.0.extract.trunc36, %for.body ], [ %v.sroa.4.0.extract.trunc, %for.body.preheader ]
|
||||||
|
%v.sroa.5.155 = phi i16 [ %v.sroa.5.0.extract.trunc38, %for.body ], [ %v.sroa.5.0.extract.trunc, %for.body.preheader ]
|
||||||
|
%v.sroa.6.154 = phi i16 [ %v.sroa.6.0.extract.trunc40, %for.body ], [ %v.sroa.6.0.extract.trunc, %for.body.preheader ]
|
||||||
|
%q64.153.pn = phi i64* [ %q64.153, %for.body ], [ %r64, %for.body.preheader ]
|
||||||
|
%q64.153 = getelementptr inbounds i64, i64* %q64.153.pn, i32 1
|
||||||
|
store i16 %v.sroa.0.157, i16* %add.ptr11.phi, align 2, !tbaa !5
|
||||||
|
store i16 %v.sroa.4.156, i16* %add.ptr16.phi, align 2, !tbaa !5
|
||||||
|
store i16 %v.sroa.5.155, i16* %add.ptr21.phi, align 2, !tbaa !5
|
||||||
|
store i16 %v.sroa.6.154, i16* %add.ptr26.phi, align 2, !tbaa !5
|
||||||
|
%2 = load i64, i64* %q64.153, align 8, !tbaa !1
|
||||||
|
%v.sroa.0.0.extract.trunc34 = trunc i64 %2 to i16
|
||||||
|
%v.sroa.4.0.extract.shift35 = lshr i64 %2, 16
|
||||||
|
%v.sroa.4.0.extract.trunc36 = trunc i64 %v.sroa.4.0.extract.shift35 to i16
|
||||||
|
%v.sroa.5.0.extract.shift37 = lshr i64 %2, 32
|
||||||
|
%v.sroa.5.0.extract.trunc38 = trunc i64 %v.sroa.5.0.extract.shift37 to i16
|
||||||
|
%v.sroa.6.0.extract.shift39 = lshr i64 %2, 48
|
||||||
|
%v.sroa.6.0.extract.trunc40 = trunc i64 %v.sroa.6.0.extract.shift39 to i16
|
||||||
|
%inc.pmt = add i32 %i.058.pmt, 1
|
||||||
|
%cmp8 = icmp slt i32 %inc.pmt, %conv
|
||||||
|
%add.ptr11.inc = getelementptr i16, i16* %add.ptr11.phi, i32 4
|
||||||
|
%add.ptr16.inc = getelementptr i16, i16* %add.ptr16.phi, i32 4
|
||||||
|
%add.ptr21.inc = getelementptr i16, i16* %add.ptr21.phi, i32 4
|
||||||
|
%add.ptr26.inc = getelementptr i16, i16* %add.ptr26.phi, i32 4
|
||||||
|
br i1 %cmp8, label %for.body, label %for.end
|
||||||
|
|
||||||
|
for.end: ; preds = %for.body, %entry
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
attributes #0 = { nounwind }
|
||||||
|
|
||||||
|
!1 = !{!2, !2, i64 0}
|
||||||
|
!2 = !{!"long long", !3, i64 0}
|
||||||
|
!3 = !{!"omnipotent char", !4, i64 0}
|
||||||
|
!4 = !{!"Simple C/C++ TBAA"}
|
||||||
|
!5 = !{!6, !6, i64 0}
|
||||||
|
!6 = !{!"short", !3, i64 0}
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: llc -march=hexagon -mcpu=hexagonv5 < %s | FileCheck %s
|
; RUN: llc -march=hexagon -mcpu=hexagonv5 -hexagon-bit=0 < %s | FileCheck %s
|
||||||
; Optimized bitwise operations.
|
; Optimized bitwise operations.
|
||||||
|
|
||||||
define i32 @my_clrbit(i32 %x) nounwind {
|
define i32 @my_clrbit(i32 %x) nounwind {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: llc -mtriple=hexagon-unknown-elf -mcpu=hexagonv5 < %s | FileCheck %s
|
; RUN: llc -mtriple=hexagon-unknown-elf -mcpu=hexagonv5 -hexagon-bit=0 < %s | FileCheck %s
|
||||||
; Optimize fabsf to clrbit in V5.
|
; Optimize fabsf to clrbit in V5.
|
||||||
|
|
||||||
; CHECK: r{{[0-9]+}} = clrbit(r{{[0-9]+}}, #31)
|
; CHECK: r{{[0-9]+}} = clrbit(r{{[0-9]+}}, #31)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: llc -march=hexagon -disable-hsdr -hexagon-expand-condsets=0 < %s | FileCheck %s
|
; RUN: llc -march=hexagon -disable-hsdr -hexagon-expand-condsets=0 -hexagon-bit=0 < %s | FileCheck %s
|
||||||
|
|
||||||
; CHECK: r{{[0-9]+:[0-9]+}} = #1
|
; CHECK: r{{[0-9]+:[0-9]+}} = #1
|
||||||
; CHECK: r{{[0-9]+:[0-9]+}} = #0
|
; CHECK: r{{[0-9]+:[0-9]+}} = #0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user