[llvm] r324560 - bpf: Improve expanding logic in LowerSELECT_CC

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 20:37:49 PST 2018


Author: yhs
Date: Wed Feb  7 20:37:49 2018
New Revision: 324560

URL: http://llvm.org/viewvc/llvm-project?rev=324560&view=rev
Log:
bpf: Improve expanding logic in LowerSELECT_CC

LowerSELECT_CC is not generating optimal Select_Ri pattern at the moment. It
is not guaranteed to place ConstantNode at RHS which would miss matching
Select_Ri.

A new testcase added into the existing select_ri.ll, also there is an
existing case in cmp.ll which would be improved to use Select_Ri after this
patch, it is adjusted accordingly.

Reported-by: Alexei Starovoitov <alexei.starovoitov at gmail.com>
Reviewed-by: Yonghong Song <yhs at fb.com>
Signed-off-by: Jiong Wang <jiong.wang at netronome.com>

Modified:
    llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp
    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=324560&r1=324559&r2=324560&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BPFISelLowering.cpp Wed Feb  7 20:37:49 2018
@@ -488,6 +488,11 @@ SDValue BPFTargetLowering::LowerSELECT_C
   SDValue TargetCC = DAG.getConstant(CC, DL, MVT::i64);
 
   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/cmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/cmp.ll?rev=324560&r1=324559&r2=324560&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/cmp.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/cmp.ll Wed Feb  7 20:37:49 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 r3 > r1
+; CHECK: if r{{[0-9]+}} {{<|>}} 100
 }
 
 ; 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=324560&r1=324559&r2=324560&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/select_ri.ll (original)
+++ llvm/trunk/test/CodeGen/BPF/select_ri.ll Wed Feb  7 20:37:49 2018
@@ -60,3 +60,28 @@ define i32 @foo(i8*) local_unnamed_addr
 
 ; Function Attrs: nounwind readonly
 declare i64 @llvm.bpf.load.word(i8*, i64) #1
+
+; Source file:
+; int m, n;
+; int test2() {
+;   int a = m;
+;   if (a < 6)
+;     a = n;
+;   return a;
+; }
+
+ at m = common local_unnamed_addr global i32 0, align 4
+ at n = common local_unnamed_addr global i32 0, align 4
+
+; Function Attrs: norecurse nounwind readonly
+define i32 @test2() local_unnamed_addr #0 {
+entry:
+  %0 = load i32, i32* @m, align 4
+  %cmp = icmp slt i32 %0, 6
+; CHECK:  if r{{[0-9]+}} s{{<|>}} 6 goto
+  %1 = load i32, i32* @n, align 4
+  %spec.select = select i1 %cmp, i32 %1, i32 %0
+  ret i32 %spec.select
+}
+
+attributes #0 = { norecurse nounwind readonly }




More information about the llvm-commits mailing list