[llvm-branch-commits] [llvm] 2460947 - BPF: Implement TTI.getCmpSelInstrCost() properly
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon May 3 16:48:47 PDT 2021
Author: Yonghong Song
Date: 2021-05-03T16:48:11-07:00
New Revision: 2460947eefc2176693a4aa4d05cd9733e38c7ffe
URL: https://github.com/llvm/llvm-project/commit/2460947eefc2176693a4aa4d05cd9733e38c7ffe
DIFF: https://github.com/llvm/llvm-project/commit/2460947eefc2176693a4aa4d05cd9733e38c7ffe.diff
LOG: BPF: Implement TTI.getCmpSelInstrCost() properly
The Select insn in BPF is expensive as BPF backend
needs to resolve with conditionals. This patch set
the getCmpSelInstrCost() to SCEVCheapExpansionBudget
for Select insn to prevent some Select insn related
optimizations.
This change is motivated during bcc code review for
https://github.com/iovisor/bcc/pull/3270
where IndVarSimplifyPass eventually caused generating
the following asm code:
; for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
14: 16 05 40 00 00 00 00 00 if w5 == 0 goto +64 <LBB0_6>
15: bc 51 00 00 00 00 00 00 w1 = w5
16: 04 01 00 00 ff ff ff ff w1 += -1
17: 67 05 00 00 20 00 00 00 r5 <<= 32
18: 77 05 00 00 20 00 00 00 r5 >>= 32
19: a6 01 01 00 05 00 00 00 if w1 < 5 goto +1 <LBB0_4>
20: b7 05 00 00 06 00 00 00 r5 = 6
00000000000000a8 <LBB0_4>:
21: b7 02 00 00 00 00 00 00 r2 = 0
22: b7 01 00 00 00 00 00 00 r1 = 0
; for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
23: 7b 1a e0 ff 00 00 00 00 *(u64 *)(r10 - 32) = r1
24: 7b 5a c0 ff 00 00 00 00 *(u64 *)(r10 - 64) = r5
Note that insn #15 has w1 = w5 and w1 is refined later but r5(w5) is
eventually saved on stack at insn #24 for later use. This cause
later verifier failures.
With this change, IndVarSimplifyPass won't do the above
transformation any more.
Differential Revision: https://reviews.llvm.org/D97479
(cherry picked from commit 1959ead525b8830cc8a345f45e1c3ef9902d3229)
Added:
Modified:
llvm/lib/Target/BPF/BPFTargetTransformInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
index 622da9a0a3f7..62055497e685 100644
--- a/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
+++ b/llvm/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -18,6 +18,7 @@
#include "BPFTargetMachine.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/CodeGen/BasicTTIImpl.h"
+#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
namespace llvm {
class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
@@ -42,6 +43,17 @@ class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> {
return TTI::TCC_Basic;
}
+
+ int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy,
+ CmpInst::Predicate VecPred,
+ TTI::TargetCostKind CostKind,
+ const llvm::Instruction *I = nullptr) {
+ if (Opcode == Instruction::Select)
+ return SCEVCheapExpansionBudget;
+
+ return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy, VecPred, CostKind,
+ I);
+ }
};
} // end namespace llvm
More information about the llvm-branch-commits
mailing list