[llvm] r329043 - bpf: fix incorrect SELECT_CC lowering
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 2 20:56:37 PDT 2018
Author: yhs
Date: Mon Apr 2 20:56:37 2018
New Revision: 329043
URL: http://llvm.org/viewvc/llvm-project?rev=329043&view=rev
Log:
bpf: fix incorrect SELECT_CC lowering
Commit 37962a331c77 ("bpf: Improve expanding logic in LowerSELECT_CC")
intended to improve code quality for certain jmp conditions. The
commit, however, has a couple of issues:
(1). In code, just swap is not enough, ConditionalCode CC
should also be swapped, otherwise incorrect code will
be generated.
(2). The ConditionalCode swap should be subject to
getHasJmpExt(). If getHasJmpExt() is False, certain
conditional codes will not be supported and swap
may generate incorrect code.
The original goal for this patch is to optimize jmp operations
which does not have JmpExt turned on. If JmpExt is on,
better code could be generated. For example, the test
select_ri.ll is introduced to demonstrate the optimization.
The same result can be achieved with -mcpu=v2 flag.
Signed-off-by: Yonghong Song <yhs at fb.com>
Acked-by: Alexei Starovoitov <ast at kernel.org>
Modified:
llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp
llvm/trunk/test/CodeGen/BPF/32-bit-subreg-peephole.ll
llvm/trunk/test/CodeGen/BPF/cmp.ll
llvm/trunk/test/CodeGen/BPF/select_ri.ll
Modified: llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp?rev=329043&r1=329042&r2=329043&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp Mon Apr 2 20:56:37 2018
@@ -502,13 +502,7 @@ SDValue BPFTargetLowering::LowerSELECT_C
NegateCC(LHS, RHS, CC);
SDValue TargetCC = DAG.getConstant(CC, DL, LHS.getValueType());
-
SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::Glue);
-
- // The constant is expected at RHS in Select_Ri pattern.
- if (isa<ConstantSDNode>(LHS.getNode()))
- std::swap(LHS, RHS);
-
SDValue Ops[] = {LHS, RHS, TargetCC, TrueV, FalseV};
return DAG.getNode(BPFISD::SELECT_CC, DL, VTs, Ops);
Modified: llvm/trunk/test/CodeGen/BPF/32-bit-subreg-peephole.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/32-bit-subreg-peephole.ll?rev=329043&r1=329042&r2=329043&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/32-bit-subreg-peephole.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/32-bit-subreg-peephole.ll Mon Apr 2 20:56:37 2018
@@ -1,4 +1,4 @@
-; RUN: llc -O2 -march=bpfel -mattr=+alu32 < %s | FileCheck %s
+; RUN: llc -O2 -march=bpfel -mcpu=v2 -mattr=+alu32 < %s | FileCheck %s
;
; long long select_u(unsigned a, unsigned b, long long c, long long d)
; {
Modified: llvm/trunk/test/CodeGen/BPF/cmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/cmp.ll?rev=329043&r1=329042&r2=329043&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/cmp.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/cmp.ll Mon Apr 2 20:56:37 2018
@@ -97,7 +97,7 @@ define zeroext i8 @minu(i8 zeroext %a, i
%a.b = select i1 %1, i8 %a, i8 %b
ret i8 %a.b
; CHECK-LABEL:minu:
-; CHECK: if r{{[0-9]+}} {{<|>}} 100
+; CHECK: if r{{[0-9]+}} {{<|>}} r{{[0-9]+}}
}
; Function Attrs: nounwind readnone uwtable
Modified: llvm/trunk/test/CodeGen/BPF/select_ri.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/select_ri.ll?rev=329043&r1=329042&r2=329043&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/select_ri.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/select_ri.ll Mon Apr 2 20:56:37 2018
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s
+; RUN: llc < %s -march=bpf -mcpu=v2 -verify-machineinstrs | FileCheck %s
;
; Source file:
; int b, c;
More information about the llvm-commits
mailing list