[llvm] Select immediate binop optimization (PR #212163)
Keith Dunwoody via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 06:07:47 PDT 2026
================
@@ -3064,6 +3064,14 @@ class LLVM_ABI TargetLoweringBase {
return Value == 0;
}
+ /// Return true if the specified immediate is legal immediate operation,
+ /// that is the target has instructions which can perform the operation
+ /// with the immediate without having to materialize the immediate into a
+ /// register.
+ virtual bool isLegalImmediate(unsigned Opc, const SDValue Val) const {
----------------
keithdunwoody wrote:
@arsenm If there's an existing target hook for this, I couldn't find it.
The closest I found was [isLegalAddImmediate](https://llvm.org/doxygen/classllvm_1_1TargetLoweringBase.html#a8ccde50eadcc47f62c4076681b969864). And I could resolve the bug I was encountering narrowly just by applying this to `add`. But the same pattern will also apply for other binary operations which allow immediates. So I was trying to follow the pattern of that function but extend to other operations.
Can you suggest a better hook? I'd also considered `isLegalBinOpImmediate()` (same signature) but decided that there's no intrinsic reason such a function should only apply to binary ops.
https://github.com/llvm/llvm-project/pull/212163
More information about the llvm-commits
mailing list