llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.94k stars 11.53k forks source link

[JumpThreading] Non-deterministic output #98750

Open dtcxzyw opened 2 months ago

dtcxzyw commented 2 months ago

Reproducer:

; ./test.sh test.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @"_ZN10ockam_node7context17context_lifecycle55_$LT$impl$u20$ockam_node..context..context..Context$GT$28copy_with_mailboxes_detached17h7c77f3fc19191f13E"() personality ptr null {
  br label %4

1:                                                ; preds = %12, %7, %2
  %.02 = phi i1 [ true, %12 ], [ true, %7 ], [ false, %2 ]
  br i1 %.02, label %13, label %14

2:                                                ; No predecessors!
  %3 = landingpad { ptr, i32 }
          cleanup
  br label %1

4:                                                ; preds = %0
  br label %5

5:                                                ; preds = %4
  %6 = invoke ptr null(ptr null)
          to label %10 unwind label %8

7:                                                ; preds = %10, %8
  %.0 = phi i1 [ true, %8 ], [ false, %10 ]
  br i1 %.0, label %12, label %1

8:                                                ; preds = %10, %5
  %9 = landingpad { ptr, i32 }
          cleanup
  br label %7

10:                                               ; preds = %5
  %11 = invoke ptr null(ptr null)
          to label %7 unwind label %8

12:                                               ; preds = %7
  br label %1

13:                                               ; preds = %1
  br label %14

14:                                               ; preds = %13, %1
  resume { ptr, i32 } zeroinitializer
}

test.sh

#!/usr/bin/bash

bin/opt -passes=jump-threading $1 -S -o diff1.ll
for i in $(seq 1 100);
do
    bin/opt -passes=jump-threading $1 -S -o diff2.ll
    diff -q diff1.ll diff2.ll
    if [ $? -ne 0 ]; then
        exit 0
    fi
done

exit 1

I have seen this happen with other Rust programs as well. I am sorry I cannot provide a test case showing actual codegen difference.

I believe it is caused by https://github.com/llvm/llvm-project/commit/f05b15b21b46835efeb88eb8bfd456e82582722c. It has caused 150+ false alarms on my benchmark https://github.com/dtcxzyw/llvm-opt-benchmark/issues?page=6&q=is%3Aissue+label%3Anon-deterministic+is%3Aclosed. It is annoying and llvm-diff doesn't work around this.

cc @kazutakahirata @nikic @MaskRay

llvmbot commented 2 months ago

@llvm/issue-subscribers-bug

Author: Yingwei Zheng (dtcxzyw)

Reproducer: ``` ; ./test.sh test.ll target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" define void @"_ZN10ockam_node7context17context_lifecycle55_$LT$impl$u20$ockam_node..context..context..Context$GT$28copy_with_mailboxes_detached17h7c77f3fc19191f13E"() personality ptr null { br label %4 1: ; preds = %12, %7, %2 %.02 = phi i1 [ true, %12 ], [ true, %7 ], [ false, %2 ] br i1 %.02, label %13, label %14 2: ; No predecessors! %3 = landingpad { ptr, i32 } cleanup br label %1 4: ; preds = %0 br label %5 5: ; preds = %4 %6 = invoke ptr null(ptr null) to label %10 unwind label %8 7: ; preds = %10, %8 %.0 = phi i1 [ true, %8 ], [ false, %10 ] br i1 %.0, label %12, label %1 8: ; preds = %10, %5 %9 = landingpad { ptr, i32 } cleanup br label %7 10: ; preds = %5 %11 = invoke ptr null(ptr null) to label %7 unwind label %8 12: ; preds = %7 br label %1 13: ; preds = %1 br label %14 14: ; preds = %13, %1 resume { ptr, i32 } zeroinitializer } ``` test.sh ``` #!/usr/bin/bash bin/opt -passes=jump-threading $1 -S -o diff1.ll for i in $(seq 1 100); do bin/opt -passes=jump-threading $1 -S -o diff2.ll diff -q diff1.ll diff2.ll if [ $? -ne 0 ]; then exit 0 fi done exit 1 ``` I have seen this happen with other ***Rust*** programs as well. I am sorry I cannot provide a test case showing actual codegen difference. I believe it is caused by https://github.com/llvm/llvm-project/commit/f05b15b21b46835efeb88eb8bfd456e82582722c. It has caused 150+ false alarms on my benchmark https://github.com/dtcxzyw/llvm-opt-benchmark/issues?page=6&q=is%3Aissue+label%3Anon-deterministic+is%3Aclosed. It is annoying and llvm-diff doesn't work around this. cc @kazutakahirata @nikic @MaskRay
nikic commented 2 months ago

I believe it is caused by https://github.com/llvm/llvm-project/commit/f05b15b21b46835efeb88eb8bfd456e82582722c.

This commit shouldn't be able to cause non-determinism, except through some indirect effect (e.g. shifting other pointer addresses due to different allocation pattern.)

dtcxzyw commented 2 months ago

It happened before 3c8f3b91d898cb3f76e1e430da98972cdf8a4a1c. Any thoughts?