File tree Expand file tree Collapse file tree 1 file changed +117
-0
lines changed
optvm/src/test/java/com/compilerprogramming/ezlang/compiler Expand file tree Collapse file tree 1 file changed +117
-0
lines changed Original file line number Diff line number Diff line change @@ -3683,4 +3683,121 @@ func main()->Int
36833683L1:
36843684""" , result );
36853685 }
3686+
3687+ @ Test
3688+ public void testSSA21 ()
3689+ {
3690+ String src = """
3691+ func eq(a: [Int], b: [Int], n: Int)->Int
3692+ {
3693+ var result = 1
3694+ var i = 0
3695+ while (i < n)
3696+ {
3697+ if (a[i] != b[i])
3698+ {
3699+ result = 0
3700+ break
3701+ }
3702+ i = i + 1
3703+ }
3704+ return result
3705+ }
3706+ """ ;
3707+ String result = compileSrc (src );
3708+ Assert .assertEquals ("""
3709+ func eq
3710+ Before SSA
3711+ ==========
3712+ L0:
3713+ arg a
3714+ arg b
3715+ arg n
3716+ result = 1
3717+ i = 0
3718+ goto L2
3719+ L2:
3720+ %t5 = i<n
3721+ if %t5 goto L3 else goto L4
3722+ L3:
3723+ %t6 = a[i]
3724+ %t7 = b[i]
3725+ %t8 = %t6!=%t7
3726+ if %t8 goto L5 else goto L6
3727+ L5:
3728+ result = 0
3729+ goto L4
3730+ L4:
3731+ ret result
3732+ goto L1
3733+ L1:
3734+ L6:
3735+ %t9 = i+1
3736+ i = %t9
3737+ goto L2
3738+ After SSA
3739+ =========
3740+ L0:
3741+ arg a_0
3742+ arg b_0
3743+ arg n_0
3744+ result_0 = 1
3745+ i_0 = 0
3746+ goto L2
3747+ L2:
3748+ i_1 = phi(i_0, i_2)
3749+ %t5_0 = i_1<n_0
3750+ if %t5_0 goto L3 else goto L4
3751+ L3:
3752+ %t6_0 = a_0[i_1]
3753+ %t7_0 = b_0[i_1]
3754+ %t8_0 = %t6_0!=%t7_0
3755+ if %t8_0 goto L5 else goto L6
3756+ L5:
3757+ result_1 = 0
3758+ goto L4
3759+ L4:
3760+ result_2 = phi(result_0, result_1)
3761+ ret result_2
3762+ goto L1
3763+ L1:
3764+ L6:
3765+ %t9_0 = i_1+1
3766+ i_2 = %t9_0
3767+ goto L2
3768+ After exiting SSA
3769+ =================
3770+ L0:
3771+ arg a_0
3772+ arg b_0
3773+ arg n_0
3774+ result_0 = 1
3775+ i_0 = 0
3776+ i_1 = i_0
3777+ goto L2
3778+ L2:
3779+ %t5_0 = i_1<n_0
3780+ result_2 = result_0
3781+ if %t5_0 goto L3 else goto L4
3782+ L3:
3783+ %t6_0 = a_0[i_1]
3784+ %t7_0 = b_0[i_1]
3785+ %t8_0 = %t6_0!=%t7_0
3786+ if %t8_0 goto L5 else goto L6
3787+ L5:
3788+ result_1 = 0
3789+ result_2 = result_1
3790+ goto L4
3791+ L4:
3792+ ret result_2
3793+ goto L1
3794+ L1:
3795+ L6:
3796+ %t9_0 = i_1+1
3797+ i_2 = %t9_0
3798+ i_1 = i_2
3799+ goto L2
3800+ """ , result );
3801+ }
3802+
36863803}
You can’t perform that action at this time.
0 commit comments