Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove br i1 undef from regression tests #115130

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

leewei05
Copy link

@leewei05 leewei05 commented Nov 6, 2024

As defined in LangRef, branching on undef is undefined behavior.
This PR aims to remove undefined behavior from tests. As UB tests break Alive2 and may be the root cause of breaking future optimizations.

Here's an Alive2 proof for one of the examples: https://alive2.llvm.org/ce/z/TncxhP

There are still many br i1 undef under llvm/test/Transforms and llvm/test/Codegen.
I'll create more PRs to fix these tests.

@nunoplopes @regehr

Copy link

github-actions bot commented Nov 6, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 6, 2024

@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-backend-systemz

Author: Lee Wei (leewei05)

Changes

As defined in LangRef, branching on undef is undefined behavior.
This PR aims to remove undefined behavior from tests. As UB tests break Alive2 and may be the root cause of breaking future optimizations.

Here's an Alive2 proof for one of the examples: https://alive2.llvm.org/ce/z/TncxhP

There are still many br i1 undef under llvm/test/Transforms and llvm/test/Codegen.
I'll create more PRs to fix these tests.

@nunoplopes @regehr


Patch is 212.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/115130.diff

91 Files Affected:

  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+4-4)
  • (modified) llvm/test/Analysis/BasicAA/underlying-value.ll (+2-2)
  • (modified) llvm/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll (+3-3)
  • (modified) llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll (+6-6)
  • (modified) llvm/test/Analysis/BranchProbabilityInfo/loop.ll (+22-22)
  • (modified) llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll (+18-18)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+2-2)
  • (modified) llvm/test/Analysis/CycleInfo/basic.ll (+50-50)
  • (modified) llvm/test/Analysis/CycleInfo/unreachable-predecessor.ll (+2-2)
  • (modified) llvm/test/Analysis/Delinearization/type_mismatch.ll (+2-2)
  • (modified) llvm/test/Analysis/Delinearization/undef.ll (+6-6)
  • (modified) llvm/test/Analysis/DependenceAnalysis/MIVCheckConst.ll (+5-5)
  • (modified) llvm/test/Analysis/DependenceAnalysis/NonAffineExpr.ll (+4-4)
  • (modified) llvm/test/Analysis/Dominators/basic.ll (+7-7)
  • (modified) llvm/test/Analysis/Dominators/print-dot-dom.ll (+7-7)
  • (modified) llvm/test/Analysis/MemoryDependenceAnalysis/invariant.group-bug.ll (+16-14)
  • (modified) llvm/test/Analysis/MemorySSA/cyclicphi.ll (+89-60)
  • (modified) llvm/test/Analysis/MemorySSA/debugvalue.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/debugvalue2.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/forward-unreachable.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/function-clobber.ll (+3-3)
  • (modified) llvm/test/Analysis/MemorySSA/invariant-groups.ll (+13-13)
  • (modified) llvm/test/Analysis/MemorySSA/loop-rotate-disablebasicaa.ll (+3-3)
  • (modified) llvm/test/Analysis/MemorySSA/loop-rotate-simplified-clone.ll (+23-3)
  • (modified) llvm/test/Analysis/MemorySSA/loop-rotate-valuemap.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/pr28880.ll (+3-3)
  • (modified) llvm/test/Analysis/MemorySSA/pr40749_2.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/pr41640.ll (+80-17)
  • (modified) llvm/test/Analysis/MemorySSA/pr41853.ll (+17-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr42294.ll (+30-14)
  • (modified) llvm/test/Analysis/MemorySSA/pr42940.ll (+147-26)
  • (modified) llvm/test/Analysis/MemorySSA/pr43317.ll (+24-8)
  • (modified) llvm/test/Analysis/MemorySSA/pr43320.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/pr43427.ll (+7-7)
  • (modified) llvm/test/Analysis/MemorySSA/pr43438.ll (+10-10)
  • (modified) llvm/test/Analysis/MemorySSA/pr43493.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43541.ll (+35-3)
  • (modified) llvm/test/Analysis/MemorySSA/pr43641.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/pr45976.ll (+37-6)
  • (modified) llvm/test/Analysis/MemorySSA/reduce_clobber_limit.ll (+105-3)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+3-3)
  • (modified) llvm/test/Analysis/MemorySSA/unreachable.ll (+2-2)
  • (modified) llvm/test/Analysis/MemorySSA/update_unroll.ll (+4-4)
  • (modified) llvm/test/Analysis/PhiValues/basic.ll (+33-33)
  • (modified) llvm/test/Analysis/PhiValues/long_phi_chain.ll (+15-15)
  • (modified) llvm/test/Analysis/PostDominators/pr6047_a.ll (+2-2)
  • (modified) llvm/test/Analysis/PostDominators/pr6047_b.ll (+3-3)
  • (modified) llvm/test/Analysis/PostDominators/pr6047_c.ll (+2-2)
  • (modified) llvm/test/Analysis/PostDominators/pr6047_d.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/2011-04-26-FoldAddRec.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll (+5-5)
  • (modified) llvm/test/Analysis/ScalarEvolution/avoid-infinite-recursion-0.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/avoid-infinite-recursion-1.ll (+24-24)
  • (modified) llvm/test/Analysis/ScalarEvolution/different-loops-recs.ll (+3-3)
  • (modified) llvm/test/Analysis/ScalarEvolution/expander-replace-congruent-ivs.ll (+12-12)
  • (modified) llvm/test/Analysis/ScalarEvolution/how-far-to-zero.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/overflow-intrinsics-trip-count.ll (+30-30)
  • (modified) llvm/test/Analysis/ScalarEvolution/pointer-sign-bits.ll (+34-34)
  • (modified) llvm/test/Analysis/ScalarEvolution/pr22674.ll (+8-8)
  • (modified) llvm/test/Analysis/ScalarEvolution/pr22856.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/pr25369.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/scev-aa.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/scev-canonical-mode.ll (+3-3)
  • (modified) llvm/test/Analysis/ScalarEvolution/scev-invalid.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/shift-recurrences.ll (+22-22)
  • (modified) llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll (+3-3)
  • (modified) llvm/test/Assembler/atomicrmw.ll (+2-2)
  • (modified) llvm/test/Assembler/convergence-control.ll (+7-7)
  • (modified) llvm/test/Bitcode/convergence-control.ll (+3-3)
  • (modified) llvm/test/DebugInfo/ARM/illegal-fragment.ll (+2-2)
  • (modified) llvm/test/DebugInfo/ARM/machine-cp-updates-dbg-reg.mir (+2-2)
  • (modified) llvm/test/DebugInfo/MIR/InstrRef/follow-spill-of-live-value.mir (+3-3)
  • (modified) llvm/test/DebugInfo/MIR/InstrRef/out-of-scope-blocks.mir (+2-2)
  • (modified) llvm/test/DebugInfo/MIR/X86/machine-cse.mir (+4-4)
  • (modified) llvm/test/DebugInfo/X86/dbg-merge-loc-entry.ll (+3-3)
  • (modified) llvm/test/DebugInfo/X86/dbg-value-terminator.ll (+19-19)
  • (modified) llvm/test/DebugInfo/X86/deleted-bit-piece.ll (+2-2)
  • (modified) llvm/test/DebugInfo/X86/earlydup-crash.ll (+4-4)
  • (modified) llvm/test/DebugInfo/X86/live-debug-values-constprop.mir (+8-8)
  • (modified) llvm/test/DebugInfo/X86/mem2reg_fp80.ll (+2-2)
  • (modified) llvm/test/DebugInfo/X86/sdag-dbgvalue-phi-use-4.ll (+2-2)
  • (modified) llvm/test/Examples/IRTransforms/SimplifyCFG/tut-simplify-cfg2-dead-block-order.ll (+2-2)
  • (modified) llvm/test/Other/loop-pass-ordering.ll (+8-8)
  • (modified) llvm/test/Other/loopnest-pass-ordering.ll (+8-8)
  • (modified) llvm/test/Other/opt-bisect-new-pass-manager.ll (+10-10)
  • (modified) llvm/test/SafepointIRVerifier/from-same-relocation-in-phi-nodes.ll (+2-2)
  • (modified) llvm/test/SafepointIRVerifier/unrecorded-live-at-sp.ll (+2-2)
  • (modified) llvm/test/SafepointIRVerifier/uses-in-phi-nodes.ll (+16-16)
  • (modified) llvm/test/Verifier/tbaa-cyclic.ll (+2-2)
  • (modified) llvm/test/tools/llvm-reduce/operands-skip.ll (+3-3)
diff --git a/llvm/test/Analysis/BasicAA/phi-values-usage.ll b/llvm/test/Analysis/BasicAA/phi-values-usage.ll
index 4c5f071ab96692..43df41c9164180 100644
--- a/llvm/test/Analysis/BasicAA/phi-values-usage.ll
+++ b/llvm/test/Analysis/BasicAA/phi-values-usage.ll
@@ -20,10 +20,10 @@ declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
 ; This function is one where if we didn't free basicaa after memcpyopt then the
 ; usage of basicaa in instcombine would cause a segfault due to stale phi-values
 ; results being used.
-define void @fn(ptr %this, ptr %ptr) personality ptr @__gxx_personality_v0 {
+define void @fn(ptr %this, ptr %ptr, i1 %arg) personality ptr @__gxx_personality_v0 {
 entry:
   %arr = alloca [4 x i8], align 8
-  br i1 undef, label %then, label %if
+  br i1 %arg, label %then, label %if
 
 if:
   br label %then
@@ -50,7 +50,7 @@ lpad:
 ; When running instcombine after memdep, the basicaa used by instcombine uses
 ; the phivalues that memdep used. This would then cause a segfault due to
 ; instcombine deleting a phi whose values had been cached.
-define void @fn2() {
+define void @fn2(i1 %arg) {
 entry:
   %a = alloca i8, align 1
   %0 = load ptr, ptr @c, align 1
@@ -58,7 +58,7 @@ entry:
 
 for.cond:                                         ; preds = %for.body, %entry
   %d.0 = phi ptr [ %0, %entry ], [ null, %for.body ]
-  br i1 undef, label %for.body, label %for.cond.cleanup
+  br i1 %arg, label %for.body, label %for.cond.cleanup
 
 for.body:                                         ; preds = %for.cond
   store volatile i8 undef, ptr %a, align 1
diff --git a/llvm/test/Analysis/BasicAA/underlying-value.ll b/llvm/test/Analysis/BasicAA/underlying-value.ll
index 4d267af8c44438..36c0c266e9a19a 100644
--- a/llvm/test/Analysis/BasicAA/underlying-value.ll
+++ b/llvm/test/Analysis/BasicAA/underlying-value.ll
@@ -3,12 +3,12 @@
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 
-define void @func_20() nounwind {
+define void @func_20(i1 %arg) nounwind {
 entry:
   br label %for.cond
 
 for.cond:                                         ; preds = %for.cond2, %entry
-  br i1 undef, label %for.cond2, label %for.end22
+  br i1 %arg, label %for.cond2, label %for.end22
 
 for.cond2:                                        ; preds = %for.body5, %for.cond
   br i1 false, label %for.body5, label %for.cond
diff --git a/llvm/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll b/llvm/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll
index b2aa0648c0a92f..09fe7e50e69cf0 100644
--- a/llvm/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll
+++ b/llvm/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll
@@ -3,10 +3,10 @@
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
-define void @fn1(ptr %f) {
+define void @fn1(ptr %f, i1 %arg) {
 entry:
   %tobool7 = icmp eq i32 undef, 0
-  br i1 undef, label %if.end.12, label %for.body.5
+  br i1 %arg, label %if.end.12, label %for.body.5
 
 for.inc:
   store i32 undef, ptr %f, align 4
@@ -19,7 +19,7 @@ for.inc.9:                                        ; preds = %for.body.5
   br i1 %tobool7, label %for.inc.9.1, label %for.inc
 
 if.end.12:                                        ; preds = %if.end.12, %for.body
-  br i1 undef, label %for.end.17, label %for.inc
+  br i1 %arg, label %for.end.17, label %for.inc
 
 for.end.17:                                       ; preds = %entry
   ret void
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll b/llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll
index f6b906b95ec6ee..0dbfdfdeb34ca6 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll
@@ -8,7 +8,7 @@ declare void @cold() cold
 
 ; Even though the likeliness of 'invoke' to throw an exception is assessed as low
 ; all other paths are even less likely. Check that hot paths leads to excepion handler.
-define void @test1(i32 %0) personality ptr @"personality_function"  !prof !1 {
+define void @test1(i32 %0, i1 %arg) personality ptr @"personality_function"  !prof !1 {
 ;CHECK: edge %entry -> %unreached probability is 0x00000001 / 0x80000000 = 0.00%
 ;CHECK: edge %entry -> %invoke probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
 ;CHECK: edge %invoke -> %invoke.cont.unreached probability is 0x00000000 / 0x80000000 = 0.00%
@@ -16,7 +16,7 @@ define void @test1(i32 %0) personality ptr @"personality_function"  !prof !1 {
 ;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %unreached, label %invoke, !prof !2
+  br i1 %arg, label %unreached, label %invoke, !prof !2
 invoke:
   invoke void @foo(i32 %0)
           to label %invoke.cont.unreached unwind label %land.pad
@@ -38,7 +38,7 @@ exit:
   ret void
 }
 
-define void @test2(i32 %0) personality ptr @"personality_function" {
+define void @test2(i32 %0, i1 %arg) personality ptr @"personality_function" {
 ;CHECK: edge %entry -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
 ;CHECK: edge %entry -> %invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ;CHECK: edge %invoke -> %invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
@@ -46,7 +46,7 @@ define void @test2(i32 %0) personality ptr @"personality_function" {
 ;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %unreached, label %invoke
+  br i1 %arg, label %unreached, label %invoke
 invoke:
   invoke void @foo(i32 %0)
           to label %invoke.cont.cold unwind label %land.pad
@@ -68,14 +68,14 @@ exit:
   ret void
 }
 
-define void @test3(i32 %0) personality ptr @"personality_function" {
+define void @test3(i32 %0, i1 %arg) personality ptr @"personality_function" {
 ;CHECK: edge %entry -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
 ;CHECK: edge %entry -> %invoke probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ;CHECK: edge %invoke -> %invoke.cont.cold probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
 ;CHECK: edge %invoke -> %land.pad probability is 0x00008000 / 0x80000000 = 0.00%
 ;CHECK: edge %land.pad -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 entry:
-  br i1 undef, label %unreached, label %invoke
+  br i1 %arg, label %unreached, label %invoke
 invoke:
   invoke void @foo(i32 %0)
           to label %invoke.cont.cold unwind label %land.pad
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/loop.ll b/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
index 0b02cedf03df3e..ffac1cd4666415 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
@@ -523,7 +523,7 @@ declare void @cold() cold
 
 ; If loop has single exit and it leads to 'cold' block then edge leading to loop enter
 ; should be considered 'cold' as well.
-define void @test13() {
+define void @test13(i1 %arg) {
 ; CHECK: edge %entry -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 ; CHECK: edge %loop -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
@@ -531,12 +531,12 @@ define void @test13() {
 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 loop:
   %i.0 = phi i32 [ 0, %entry ], [ %inc, %loop ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %loop, label %cold
+  br i1 %arg, label %loop, label %cold
 
 cold:
   call void @cold()
@@ -547,7 +547,7 @@ exit:
 }
 
 ; This is the same case as test13 but with additional loop 'preheader' block.
-define void @test14() {
+define void @test14(i1 %arg) {
 ; CHECK: edge %entry -> %preheader probability is 0x078780e3 / 0x80000000 = 5.88%
 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 ; CHECK: edge %preheader -> %loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
@@ -556,7 +556,7 @@ define void @test14() {
 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %preheader, label %exit
+  br i1 %arg, label %preheader, label %exit
 
 preheader:
   br label %loop
@@ -564,7 +564,7 @@ preheader:
 loop:
   %i.0 = phi i32 [ 0, %preheader ], [ %inc, %loop ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %loop, label %cold
+  br i1 %arg, label %loop, label %cold
 
 cold:
   call void @cold()
@@ -576,7 +576,7 @@ exit:
 
 ; If loop has multiple low probability exits then edge leading to loop enter
 ; should be considered low probable as well.
-define void @test15() {
+define void @test15(i1 %arg) {
 ; CHECK: edge %entry -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 ; CHECK: edge %loop -> %cont probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
@@ -586,15 +586,15 @@ define void @test15() {
 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 loop:
   %i.0 = phi i32 [ 0, %entry ], [ %inc, %cont ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %cont, label %unreached
+  br i1 %arg, label %cont, label %unreached
 
 cont:
-  br i1 undef, label %loop, label %cold
+  br i1 %arg, label %loop, label %cold
 
 unreached:
   unreachable
@@ -609,7 +609,7 @@ exit:
 }
 
 ; This is the same case as test15 but with additional loop 'preheader' block.
-define void @test16() {
+define void @test16(i1 %arg) {
 ; CHECK: edge %entry -> %preheader probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ; CHECK: edge %preheader -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
 ; CHECK: edge %preheader -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
@@ -623,15 +623,15 @@ entry:
   br label %preheader
 
 preheader:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 loop:
   %i.0 = phi i32 [ 0, %preheader ], [ %inc, %cont ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %cont, label %unreached
+  br i1 %arg, label %cont, label %unreached
 
 cont:
-  br i1 undef, label %loop, label %cold
+  br i1 %arg, label %loop, label %cold
 
 unreached:
   unreachable
@@ -649,7 +649,7 @@ declare void @abort() noreturn
 
 ; Check that 'preheader' has 50/50 probability since there is one 'normal' exit.
 ; Check that exit to 'cold' and 'noreturn' has lower probability than 'normal' exit.
-define void @test17() {
+define void @test17(i1 %arg) {
 ; CHECK: edge %entry -> %preheader probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ; CHECK: edge %preheader -> %loop probability is 0x40000000 / 0x80000000 = 50.00%
 ; CHECK: edge %preheader -> %exit probability is 0x40000000 / 0x80000000 = 50.00%
@@ -664,18 +664,18 @@ entry:
   br label %preheader
 
 preheader:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 loop:
   %i.0 = phi i32 [ 0, %preheader ], [ %inc, %cont2 ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %cont, label %noreturn
+  br i1 %arg, label %cont, label %noreturn
 
 cont:
-  br i1 undef, label %cont2, label %cold
+  br i1 %arg, label %cont2, label %cold
 
 cont2:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 noreturn:
   call void @abort()
@@ -692,7 +692,7 @@ exit:
 
 ; This is case with two loops where one nested into another. Nested loop has
 ; low probable exit what encreases robability to take exit in the top level loop.
-define void @test18() {
+define void @test18(i1 %arg) {
 ; CHECK: edge %entry -> %top.loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ; CHECK: edge %top.loop -> %loop probability is 0x546cd4b7 / 0x80000000 = 65.96%
 ; CHECK: edge %top.loop -> %exit probability is 0x2b932b49 / 0x80000000 = 34.04%
@@ -705,12 +705,12 @@ entry:
 
 top.loop:
   %j.0 = phi i32 [ 0, %entry ], [ %j.inc, %cold ]
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 loop:
   %i.0 = phi i32 [ %j.0, %top.loop ], [ %inc, %loop ]
   %inc = add nsw i32 %i.0, 1
-  br i1 undef, label %loop, label %cold
+  br i1 %arg, label %loop, label %cold
 
 cold:
   call void @cold()
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll b/llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll
index d3ada520c4dac9..1de1893a729111 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll
@@ -5,7 +5,7 @@ declare void @bar() cold
 ; Both 'l1' and 'r1' has one edge leading to 'cold' and another one to
 ; 'unreachable' blocks. Check that 'cold' paths are preferred. Also ensure both
 ; paths from 'entry' block are equal.
-define void @test1(i32 %0) {
+define void @test1(i32 %0, i1 %arg) {
 ;CHECK: edge %entry -> %l1 probability is 0x40000000 / 0x80000000 = 50.00%
 ;CHECK: edge %entry -> %r1 probability is 0x40000000 / 0x80000000 = 50.00%
 ;CHECK: edge %l1 -> %cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
@@ -14,13 +14,13 @@ define void @test1(i32 %0) {
 ;CHECK: edge %r1 -> %cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %l1, label %r1
+  br i1 %arg, label %l1, label %r1
 
 l1:
-  br i1 undef, label %cold, label %unreached
+  br i1 %arg, label %cold, label %unreached
 
 r1:
-  br i1 undef, label %unreached, label %cold
+  br i1 %arg, label %unreached, label %cold
 
 unreached:
   unreachable
@@ -33,7 +33,7 @@ cold:
 ; Both edges of 'l1' leads to 'cold' blocks while one edge of 'r1' leads to
 ; 'unreachable' block. Check that 'l1' has 50/50 while 'r1' has 0/100
 ; distributuion. Also ensure both paths from 'entry' block are equal.
-define void @test2(i32 %0) {
+define void @test2(i32 %0, i1 %arg) {
 ;CHECK: edge %entry -> %l1 probability is 0x40000000 / 0x80000000 = 50.00%
 ;CHECK: edge %entry -> %r1 probability is 0x40000000 / 0x80000000 = 50.00%
 ;CHECK: edge %l1 -> %cold probability is 0x40000000 / 0x80000000 = 50.00%
@@ -42,13 +42,13 @@ define void @test2(i32 %0) {
 ;CHECK: edge %r1 -> %cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %l1, label %r1
+  br i1 %arg, label %l1, label %r1
 
 l1:
-  br i1 undef, label %cold, label %cold2
+  br i1 %arg, label %cold, label %cold2
 
 r1:
-  br i1 undef, label %unreached, label %cold
+  br i1 %arg, label %unreached, label %cold
 
 unreached:
   unreachable
@@ -64,7 +64,7 @@ cold2:
 
 ; Both edges of 'r1' leads to 'unreachable' blocks while one edge of 'l1' leads to
 ; 'cold' block. Ensure that path leading to 'cold' block is preferred.
-define void @test3(i32 %0) {
+define void @test3(i32 %0, i1 %arg) {
 ;CHECK: edge %entry -> %l1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 ;CHECK: edge %entry -> %r1 probability is 0x00000000 / 0x80000000 = 0.00%
 ;CHECK: edge %l1 -> %cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
@@ -73,13 +73,13 @@ define void @test3(i32 %0) {
 ;CHECK: edge %r1 -> %unreached2 probability is 0x40000000 / 0x80000000 = 50.00%
 
 entry:
-  br i1 undef, label %l1, label %r1
+  br i1 %arg, label %l1, label %r1
 
 l1:
-  br i1 undef, label %cold, label %unreached
+  br i1 %arg, label %cold, label %unreached
 
 r1:
-  br i1 undef, label %unreached, label %unreached2
+  br i1 %arg, label %unreached, label %unreached2
 
 unreached:
   unreachable
@@ -95,7 +95,7 @@ cold:
 ; Left edge of 'entry' leads to 'cold' block while right edge is 'normal' continuation.
 ; Check that we able to propagate 'cold' weight to 'entry' block. Also ensure
 ; both edges from 'l1' are equally likely.
-define void @test4(i32 %0) {
+define void @test4(i32 %0, i1 %arg) {
 ;CHECK: edge %entry -> %l1 probability is 0x078780e3 / 0x80000000 = 5.88%
 ;CHECK: edge %entry -> %r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 ;CHECK: edge %l1 -> %l2 probability is 0x40000000 / 0x80000000 = 50.00%
@@ -105,10 +105,10 @@ define void @test4(i32 %0) {
 ;CHECK: edge %to.cold -> %cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
 
 entry:
-  br i1 undef, label %l1, label %r1
+  br i1 %arg, label %l1, label %r1
 
 l1:
-  br i1 undef, label %l2, label %r2
+  br i1 %arg, label %l2, label %r2
 
 l2:
   br label %to.cold
@@ -128,7 +128,7 @@ cold:
 }
 
 ; Check that most likely path from 'entry' to 'l2' through 'r1' is preferred.
-define void @test5(i32 %0) {
+define void @test5(i32 %0, i1 %arg) {
 ;CHECK: edge %entry -> %cold probability is 0x078780e3 / 0x80000000 = 5.88%
 ;CHECK: edge %entry -> %r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
 ;CHECK: edge %cold -> %l2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
@@ -136,14 +136,14 @@ define void @test5(i32 %0) {
 ;CHECK: edge %r1 -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
 
 entry:
-  br i1 undef, label %cold, label %r1
+  br i1 %arg, label %cold, label %r1
 
 cold:
   call void @bar()
   br label %l2
 
 r1:
-  br i1 undef, label %l2, label %unreached
+  br i1 %arg, label %l2, label %unreached
 
 l2:
   ret void
diff --git a/llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll b/llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll
index d8a864a85ed59d..ecc7fc8fdb98a0 100644
--- a/llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll
+++ b/llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll
@@ -26,12 +26,12 @@
 declare void @llvm.lifetime.end(i64, ptr nocapture) #0
 
 ; Function Attrs: nounwind ssp uwtable
-define hidden void @fun(ptr %N) #1 align 2 {
+define hidden void @fun(ptr %N, i1 %arg) #1 align 2 {
 ; CHECK: define
 entry:
   %NumOperands.i = getelementptr inbounds %"class.llvm::SDNode.310.1762.9990.10474.10958.11442.11926.12410.12894.13378.13862.15314.15798.16282.17734.19186.21122.25962.26930.29350.29834.30318.30802.31286.31770.32254.32738.33706.36610.38062.41642", ptr %N, i64 0, i32 8
   %0 = load i16, ptr %NumOperands.i, align 8, !tbaa !1
-  br i1 undef, label %for.cond.cleanup, label %for.body.lr.ph
+  br i1 %arg, label %for.cond.cleanup, label %for.body.lr.ph
 
 for.body.lr.ph:                                   ; preds = %entry
   %wide.trip.count192 = zext i16 %0 to i64
diff --git a/llvm/test/Analysis/CycleInfo/basic.ll b/llvm/test/Analysis/CycleInfo/basic.ll
index e459b0c317f948..33e5227b162fd3 100644
--- a/llvm/test/Analysis/CycleInfo/basic.ll
+++ b/llvm/test/Analysis/CycleInfo/basic.ll
@@ -7,36 +7,36 @@ define void @empty() {
   ret void
 }
 
-define void @simple() {
+define void @simple(i1 %arg) {
 ; CHECK-LABEL: CycleInfo for function: simple
 ; CHECK:           depth=1: entries(loop)
 entry:
   br label %loop
 
 loop:
-  br i1 undef, label %loop, label %exit
+  br i1 %arg, label %loop, label %exit
 
 exit:
   ret void
 }
 
-define void @two_latches() {
+define void @two_latches(i1 %arg) {
 ; CHECK-LABEL: CycleInfo for function: two_latches
 ; CHECK:           depth=1: entries(loop) loop_next
 entry:
   br label %loop
 
 loop:
-  br i1 undef, label %loop, label %loop_next
+  br i1 %arg, label %loop, label %loop_next
 
 loop_next:
-  br i1 undef, label %exit, label %loop
+  br i1 %arg, label %exit, label %loop
 
 exit:
   ret void
 }
 
-define void @nested_simple() {
+define void @nested_simple(i1 %arg) {
 ; CHECK-LABEL: CycleInfo for function: nested_simple
 ; CHECK:           depth=1: entries(outer_header) outer_latch inner
 ; CHECK:               depth=2: entries(inner)
@@ -47,16 +47,16 @@ outer_header:
   br label %inner
 
 inner:
-  br i1 undef, label %inner, label %outer_latch
+  br i1 %arg, label %inner, label %outer_latch
 
 outer_latch:
-  br i1 undef, label %outer_header, label %exit
+  br i1 %arg, label %outer_header, label %exit
 
 exit:
   ret void
 }
 
-define void @nested_outer_latch_in_inner_loop() {
+define void @nested_outer_latch_in_inner_loop(i1 %arg) {
 ; CHECK-LABEL: CycleInfo for function: nested_outer_latch_in_inner_loop
 ; CHECK:           depth=1: entries(outer_header) inner_header inner_latch
 ; CHECK:               depth=2: entries(inner_header) inner_latch
@@ -67,33 +67...
[truncated]

Copy link
Member

@nunoplopes nunoplopes left a comment

Choose a reason for hiding this comment

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

Great work, thanks!

The MemorySSA tests you changed to use the automatic output checking must be reverted. You must keep the old checks. The auto-generated ones aren't checking the same thing. The old ones were checking that the memory phis were in the right place.

Copy link
Member

@jmorse jmorse left a comment

Choose a reason for hiding this comment

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

The changes in the DebugInfo directory look good.

I get the feeling that earlydup-crash.ll is the most likely to accidentally lose some tests coverage, as it's a crash-test with a broad input that (potentially) generates substantially different code for well-defined branches rather than undef branches. However, given that IIRC undef branches will eventually not be supported by LLVM, this is unavoidable.

@nunoplopes
Copy link
Member

The changes in the DebugInfo directory look good.

I get the feeling that earlydup-crash.ll is the most likely to accidentally lose some tests coverage, as it's a crash-test with a broad input that (potentially) generates substantially different code for well-defined branches rather than undef branches. However, given that IIRC undef branches will eventually not be supported by LLVM, this is unavoidable.

ok, then we can leave that test with br poison instead, so it gets out of the conversion queue, while keeping the coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants