[llvm] [ConstraintElimination] Add eq/ne facts to signed constraint system (PR #121423)

Stephen Senran Zhang via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 00:41:58 PST 2025


================
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
+
+define i1 @f(i32 noundef %v0, i32 noundef %v1, i32 noundef %v2)  {
+; CHECK-LABEL: define i1 @f(
+; CHECK-SAME: i32 noundef [[V0:%.*]], i32 noundef [[V1:%.*]], i32 noundef [[V2:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[V2]], [[V0]]
----------------
zsrkmyn wrote:

Actually, `addFact` doesn't handle `ne` cases for now. See https://github.com/llvm/llvm-project/blob/bd4a323db717df22b94d27b0eab49b05a06ae4bb/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp#L1613

I think the reason is that the constraint system now models all constraints as `c0 * var0 + c1 * var1 + ... <= const`, and for `x eq y`, and we can model it as `x - y <= 0` + `-x + y <= 0`; but for `ne`, we cannot do so. @fhahn do I understand it right?

For the completeness of the patch, I still try to add `ne` into the signed system, and hope we'll support it in the future :-D But I'm fine to remove it if it's unnecessary.


https://github.com/llvm/llvm-project/pull/121423


More information about the llvm-commits mailing list