[all-commits] [llvm/llvm-project] e52946: BPF: avoid NE/EQ loop exit condition
yonghong-song via All-commits
all-commits at lists.llvm.org
Wed Aug 4 16:54:37 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e52946b9ababcbf8e6f40b1b15900ae2e795a1c6
https://github.com/llvm/llvm-project/commit/e52946b9ababcbf8e6f40b1b15900ae2e795a1c6
Author: Yonghong Song <yhs at fb.com>
Date: 2021-08-04 (Wed, 04 Aug 2021)
Changed paths:
M llvm/lib/Target/BPF/BPFTargetTransformInfo.h
A llvm/test/CodeGen/BPF/loop-exit-cond.ll
Log Message:
-----------
BPF: avoid NE/EQ loop exit condition
Kuniyuki Iwashima reported in [1] that llvm compiler may
convert a loop exit condition with "i < bound" to "i != bound", where
"i" is the loop index variable and "bound" is the upper bound.
In case that "bound" is not a constant, verifier will always have "i != bound"
true, which will cause verifier failure since to verifier this is
an infinite loop.
The fix is to avoid transforming "i < bound" to "i != bound".
In llvm, the transformation is done by IndVarSimplify pass.
The compiler checks loop condition cost (i = i + 1) and if the
cost is lower, it may transform "i < bound" to "i != bound".
This patch implemented getArithmeticInstrCost() in BPF TargetTransformInfo
class to return a higher cost for such an operation, which
will prevent the transformation for the test case
added in this patch.
[1] https://lore.kernel.org/netdev/1994df05-8f01-371f-3c3b-d33d7836878c@fb.com/
Differential Revision: https://reviews.llvm.org/D107483
More information about the All-commits
mailing list