[llvm] b341c44 - [SimpleLoopUnswitch] Check if freeze is needed for partial unswitching.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 13:27:28 PDT 2022
Author: Florian Hahn
Date: 2022-04-22T21:24:55+01:00
New Revision: b341c440102d1182953f7a23be2c457d1fda8b6d
URL: https://github.com/llvm/llvm-project/commit/b341c440102d1182953f7a23be2c457d1fda8b6d
DIFF: https://github.com/llvm/llvm-project/commit/b341c440102d1182953f7a23be2c457d1fda8b6d.diff
LOG: [SimpleLoopUnswitch] Check if freeze is needed for partial unswitching.
We only need to insert a Freeze instruction if any of the conditions
may be poison. Similar checks are already done in the other places
SimpleLoopUnswitch creates Freeze instruction.
Reviewed By: aeubanks, efriedma
Differential Revision: https://reviews.llvm.org/D124259
Added:
Modified:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index cf19357f87ff8..7a29dbdc8be63 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -2313,9 +2313,13 @@ static void unswitchNontrivialInvariants(
if (PartiallyInvariant)
buildPartialInvariantUnswitchConditionalBranch(
*SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, L, MSSAU);
- else
- buildPartialUnswitchConditionalBranch(*SplitBB, Invariants, Direction,
- *ClonedPH, *LoopPH, InsertFreeze);
+ else {
+ buildPartialUnswitchConditionalBranch(
+ *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH,
+ InsertFreeze && any_of(Invariants, [&](Value *C) {
+ return !isGuaranteedNotToBeUndefOrPoison(C, &AC, BI, &DT);
+ }));
+ }
DTUpdates.push_back({DominatorTree::Insert, SplitBB, ClonedPH});
if (MSSAU) {
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
index 8ccc9d429e635..7b8cf5fd85778 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-freeze.ll
@@ -2333,8 +2333,7 @@ define i32 @test_partial_unswitch_all_conds_guaranteed_non_poison(i1 noundef %c.
; CHECK-LABEL: @test_partial_unswitch_all_conds_guaranteed_non_poison(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = and i1 [[C_1:%.*]], [[C_2:%.*]]
-; CHECK-NEXT: [[DOTFR:%.*]] = freeze i1 [[TMP0]]
-; CHECK-NEXT: br i1 [[DOTFR]], label [[ENTRY_SPLIT:%.*]], label [[ENTRY_SPLIT_US:%.*]]
+; CHECK-NEXT: br i1 [[TMP0]], label [[ENTRY_SPLIT:%.*]], label [[ENTRY_SPLIT_US:%.*]]
; CHECK: entry.split.us:
; CHECK-NEXT: br label [[LOOP_US:%.*]]
; CHECK: loop.us:
More information about the llvm-commits
mailing list