Skip to content

Commit

Permalink
Added simplification of IfBranch terminators.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Sep 1, 2023
1 parent f75ecb4 commit 10323d0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Src/ILGPU/IR/Construction/Terminators.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2018-2021 ILGPU Project
// Copyright (c) 2018-2023 ILGPU Project
// www.ilgpu.net
//
// File: Terminators.cs
Expand Down Expand Up @@ -87,13 +87,20 @@ public Branch CreateIfBranch(
Value condition,
BasicBlock trueTarget,
BasicBlock falseTarget,
IfBranchFlags flags) =>
CreateTerminator(new IfBranch(
IfBranchFlags flags)
{
// Simplify unnecessary if branches and fold them to unconditional branches
if (trueTarget == falseTarget)
return CreateBranch(location, trueTarget);

// Create an if branch in all other cases
return CreateTerminator(new IfBranch(
GetInitializer(location),
condition,
trueTarget,
falseTarget,
flags));
}

/// <summary>
/// Creates a switch terminator builder.
Expand Down

0 comments on commit 10323d0

Please sign in to comment.