Skip to content

Commit

Permalink
[ConstraintElim] Treat ConstantPointerNull as constant offset 0.
Browse files Browse the repository at this point in the history
Treat ConstantPointerNull (null) as constant offset 0 in the constraint
instead of a variable. This slightly reduces the number of variables. I
was not able to find a test case where this actually caused any changes.
  • Loading branch information
fhahn committed Nov 22, 2023
1 parent 6f0c52e commit 2362813
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Expand Up @@ -455,6 +455,9 @@ static Decomposition decompose(Value *V,
if (Ty->isPointerTy() && !IsSigned) {
if (auto *GEP = dyn_cast<GEPOperator>(V))
return decomposeGEP(*GEP, Preconditions, IsSigned, DL);
if (isa<ConstantPointerNull>(V))
return int64_t(0);

return V;
}

Expand Down

2 comments on commit 2362813

@nathanchance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to cause a test failure for me on x86_64 Linux with assertions enabled:

$ cmake \
    -B build \
    -G Ninja \
    -S llvm \
    --log-level=NOTICE \
    -Wno-dev \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DLLVM_ENABLE_ASSERTIONS=true \
    -DLLVM_ENABLE_PROJECTS=llvm \
    -DLLVM_USE_LINKER=lld
...

$ ninja -C build check-llvm
...
[4126/4127] Running the LLVM regression tests
FAIL: LLVM :: Transforms/ConstraintElimination/reproducer-remarks-debug.ll (36637 of 52970)
******************** TEST 'LLVM :: Transforms/ConstraintElimination/reproducer-remarks-debug.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /mnt/nvme/tmp/build/llvm/bin/opt -passes=constraint-elimination -constraint-elimination-dump-reproducers -pass-remarks=constraint-elimination -debug /home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll 2>&1 | /mnt/nvme/tmp/build/llvm/bin/FileCheck /home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll
+ /mnt/nvme/tmp/build/llvm/bin/opt -passes=constraint-elimination -constraint-elimination-dump-reproducers -pass-remarks=constraint-elimination -debug /home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll
+ /mnt/nvme/tmp/build/llvm/bin/FileCheck /home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll
/home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll:8:15: error: CHECK-NEXT: expected string not found in input
; CHECK-NEXT: %a + -1 * null <= 0
              ^
<stdin>:22:72: note: scanning from here
Condition %c.2 = icmp eq ptr %a, null implied by dominating constraints
                                                                       ^
<stdin>:33:7: note: possible intended match here
 constraint: -1 * %a <= -1
      ^

Input file: <stdin>
Check file: /home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
          .
          .
          .
         17: Checking %c.2 = icmp eq ptr %a, null
         18: ---
         19: %a <= 0
         20: -1 * %a <= -1
         21: unsat
         22: Condition %c.2 = icmp eq ptr %a, null implied by dominating constraints
next:8'0                                                                            X error: no match found
         23: %a <= 0
next:8'0     ~~~~~~~~
         24: Creating reproducer for %c.2 = icmp eq ptr %a, null
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         25:  found external input ptr %a
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         26:  Materializing assumption icmp eq ptr %a, null
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         27: Top of stack : 1 2
next:8'0     ~~~~~~~~~~~~~~~~~~~
         28: CB: 3 4
next:8'0     ~~~~~~~~
         29: Removing %a <= 0
next:8'0     ~~~~~~~~~~~~~~~~~
         30:
next:8'0     ~
         31: Processing fact to add to the system: ne ptr %a, null
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         32: Adding 'ne %a, null'
next:8'0     ~~~~~~~~~~~~~~~~~~~~~
         33:  constraint: -1 * %a <= -1
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
next:8'1           ?                     possible intended match
         34:
next:8'0     ~
         35: remark: <unknown>:0:0: module; ModuleID = 'test_ptr_null_constant'
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         36: source_filename = "test_ptr_null_constant"
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         37:
next:8'0     ~
         38: define i1 @"/home/nathan/cbl/src/llvm-project/llvm/test/Transforms/ConstraintElimination/reproducer-remarks-debug.lltest_ptr_null_constantrepro"(ptr %a) {
next:8'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          .
          .
          .
>>>>>>

--

********************
********************
Failed Tests (1):
  LLVM :: Transforms/ConstraintElimination/reproducer-remarks-debug.ll
...

@fhahn
Copy link
Contributor Author

@fhahn fhahn commented on 2362813 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, reverted for now

Please sign in to comment.