From dcb6543de5faf3222817cdb358f038d24857546a Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sat, 21 May 2016 00:29:34 +0000 Subject: [PATCH] AMDGPU: Implement ReverseBranchCondition git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270296 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AMDGPU/SIInstrInfo.cpp | 7 +++++++ lib/Target/AMDGPU/SIInstrInfo.h | 3 +++ test/CodeGen/AMDGPU/uniform-cfg.ll | 8 ++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Target/AMDGPU/SIInstrInfo.cpp b/lib/Target/AMDGPU/SIInstrInfo.cpp index 64416e80d59..7b232ba7b8b 100644 --- a/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -1166,6 +1166,13 @@ unsigned SIInstrInfo::InsertBranch(MachineBasicBlock &MBB, return 2; } +bool SIInstrInfo::ReverseBranchCondition( + SmallVectorImpl &Cond) const { + assert(Cond.size() == 1); + Cond[0].setImm(-Cond[0].getImm()); + return false; +} + static void removeModOperands(MachineInstr &MI) { unsigned Opc = MI.getOpcode(); int Src0ModIdx = AMDGPU::getNamedOperandIdx(Opc, diff --git a/lib/Target/AMDGPU/SIInstrInfo.h b/lib/Target/AMDGPU/SIInstrInfo.h index 4e37372a991..46705cd0b7d 100644 --- a/lib/Target/AMDGPU/SIInstrInfo.h +++ b/lib/Target/AMDGPU/SIInstrInfo.h @@ -157,6 +157,9 @@ public: MachineBasicBlock *FBB, ArrayRef Cond, DebugLoc DL) const override; + bool ReverseBranchCondition( + SmallVectorImpl &Cond) const override; + bool areMemAccessesTriviallyDisjoint( MachineInstr *MIa, MachineInstr *MIb, AliasAnalysis *AA = nullptr) const override; diff --git a/test/CodeGen/AMDGPU/uniform-cfg.ll b/test/CodeGen/AMDGPU/uniform-cfg.ll index 87a4739ae22..dfc82f820cc 100644 --- a/test/CodeGen/AMDGPU/uniform-cfg.ll +++ b/test/CodeGen/AMDGPU/uniform-cfg.ll @@ -168,10 +168,8 @@ endif: ; SI-LABEL: {{^}}uniform_if_else_ret: ; SI: s_cmp_lg_i32 s{{[0-9]+}}, 0 -; SI-NEXT: s_cbranch_scc1 [[ELSE_LABEL:[0-9_A-Za-z]+]] -; SI-NEXT: s_branch [[IF_LABEL:[0-9_A-Za-z]+]] +; SI-NEXT: s_cbranch_scc0 [[IF_LABEL:[0-9_A-Za-z]+]] -; SI: [[ELSE_LABEL]]: ; SI: v_mov_b32_e32 [[TWO:v[0-9]+]], 2 ; SI: buffer_store_dword [[TWO]] ; SI: s_endpgm @@ -199,10 +197,8 @@ if.end: ; preds = %if.else, %if.then ; SI-LABEL: {{^}}uniform_if_else: ; SI: s_cmp_lg_i32 s{{[0-9]+}}, 0 -; SI-NEXT: s_cbranch_scc1 [[ELSE_LABEL:[0-9_A-Za-z]+]] -; SI-NEXT: s_branch [[IF_LABEL:[0-9_A-Za-z]+]] +; SI-NEXT: s_cbranch_scc0 [[IF_LABEL:[0-9_A-Za-z]+]] -; SI: [[ELSE_LABEL]]: ; SI: v_mov_b32_e32 [[TWO:v[0-9]+]], 2 ; SI: buffer_store_dword [[TWO]] ; SI: s_branch [[ENDIF_LABEL:[0-9_A-Za-z]+]]