[llvm] [InstSimplify] Implement simple folds for `ucmp`/`scmp` intrinsics (PR #95601)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 15 07:32:38 PDT 2024
================
@@ -6505,6 +6505,33 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
break;
}
+ case Intrinsic::scmp:
+ case Intrinsic::ucmp: {
+ // Fold cmp x, x -> 0
+ if (Op0 == Op1)
+ return Constant::getNullValue(ReturnType);
----------------
nikic wrote:
The rule of thumb is that you only need to optimize the case where things do *not* fold, because not folding is the common case. Unless a substantial fraction of inputs contain cmp(x, x), having a special case for it will make no difference.
If we wanted to optimize this, then we could drop the ICMP_EQ query instead, and argue that cases where the values are non-trivially equal should be handled by GVN instead. But I think it's fine to keep the general implementation for now.
https://github.com/llvm/llvm-project/pull/95601
More information about the llvm-commits
mailing list