[clang] [llvm] [IR] Optimize PHINode::removeIncomingValue() by swapping removed incoming value with the last incoming value. (PR #171963)
Mingjie Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 30 03:28:46 PST 2025
Enna1 wrote:
I think I reproduced the non-determinism with repeatedly running https://github.com/dtcxzyw/llvm-opt-benchmark/blob/299446d99f04024d5f569ce1f7e9338c9bcf55fe/bench/wolfssl/original/internal.ll
```
opt -O3 -disable-loop-unrolling -vectorize-loops=false -vectorize-slp=false -S wolfssl/original/internal.ll -o wolfssl-internal.opt.ll
```
``` diff
--- wolfssl-internal.opt.ll 2025-12-30 14:23:44.748430947 +0800
+++ wolfssl-internal.opt.test.ll 2025-12-30 14:24:58.060504541 +0800
@@ -21855,8 +21855,8 @@
store i32 %94, ptr %1, align 4, !tbaa !49
br label %AllocKey.exit.thread
-AllocKey.exit.thread: ; preds = %64, %77, %73, %17, %26, %13, %30, %85, %FreeKey.exit, %42, %38, %7, %2, %AllocKey.exit60, %92, %47
- %.0 = phi i32 [ %.1, %FreeKey.exit ], [ -410, %85 ], [ -317, %7 ], [ %40, %38 ], [ 0, %47 ], [ %25, %30 ], [ -409, %42 ], [ 0, %92 ], [ %83, %AllocKey.exit60 ], [ -317, %2 ], [ -125, %17 ], [ %25, %26 ], [ -192, %13 ], [ -125, %64 ], [ %72, %77 ], [ %72, %73 ]
+AllocKey.exit.thread: ; preds = %64, %73, %77, %17, %30, %13, %26, %85, %FreeKey.exit, %42, %38, %7, %2, %AllocKey.exit60, %92, %47
+ %.0 = phi i32 [ %.1, %FreeKey.exit ], [ -410, %85 ], [ -317, %7 ], [ %40, %38 ], [ 0, %47 ], [ %25, %26 ], [ -409, %42 ], [ 0, %92 ], [ %83, %AllocKey.exit60 ], [ -317, %2 ], [ -125, %17 ], [ %25, %30 ], [ -192, %13 ], [ -125, %64 ], [ %72, %73 ], [ %72, %77 ]
call void @llvm.lifetime.end.p0(ptr nonnull %3)
ret i32 %.0
}
```
The order of phi incoming values maybe different in multiple runs...
https://github.com/llvm/llvm-project/pull/173975 should fix this.
https://github.com/llvm/llvm-project/pull/171963
More information about the cfe-commits
mailing list