[llvm] e4d751c - Update BPFAdjustOpt.cpp to accept select form of or as well

Juneyoung Lee via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 20 01:30:10 PST 2021


Author: Juneyoung Lee
Date: 2021-02-20T18:29:58+09:00
New Revision: e4d751c271a5dfec12953b67d4fb88a1dd00920f

URL: https://github.com/llvm/llvm-project/commit/e4d751c271a5dfec12953b67d4fb88a1dd00920f
DIFF: https://github.com/llvm/llvm-project/commit/e4d751c271a5dfec12953b67d4fb88a1dd00920f.diff

LOG: Update BPFAdjustOpt.cpp to accept select form of or as well

This is a minor pattern-match update to BPFAdjustOpt.cpp to accept
not only 'or i1 a, b' but also 'select i1 a, i1 true, i1 b'.
This resolves regression after SimplifyCFG's creating select form
of and/or instead (https://reviews.llvm.org/D95026).
This is a small change, and currently such select form isn't created
or doesn't reach to the late pipeline (because InstCombine eagerly
folds it into and/or i1), so I chose to commit without a review process.

Added: 
    

Modified: 
    llvm/lib/Target/BPF/BPFAdjustOpt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
index f40d8ac03e49..7088d55e1a71 100644
--- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -16,6 +16,7 @@
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
@@ -25,6 +26,7 @@
 #define DEBUG_TYPE "bpf-adjust-opt"
 
 using namespace llvm;
+using namespace llvm::PatternMatch;
 
 static cl::opt<bool>
     DisableBPFserializeICMP("bpf-disable-serialize-icmp", cl::Hidden,
@@ -115,12 +117,14 @@ bool BPFAdjustOptImpl::serializeICMPInBB(Instruction &I) {
   //   comp2 = icmp <opcode> ...;
   //   new_comp1 = __builtin_bpf_passthrough(seq_num, comp1)
   //   ... or new_comp1 comp2 ...
-  if (I.getOpcode() != Instruction::Or)
+  Value *Op0, *Op1;
+  // Use LogicalOr (accept `or i1` as well as `select i1 Op0, true, Op1`)
+  if (!match(&I, m_LogicalOr(m_Value(Op0), m_Value(Op1))))
     return false;
-  auto *Icmp1 = dyn_cast<ICmpInst>(I.getOperand(0));
+  auto *Icmp1 = dyn_cast<ICmpInst>(Op0);
   if (!Icmp1)
     return false;
-  auto *Icmp2 = dyn_cast<ICmpInst>(I.getOperand(1));
+  auto *Icmp2 = dyn_cast<ICmpInst>(Op1);
   if (!Icmp2)
     return false;
 


        


More information about the llvm-commits mailing list