@@ -300,12 +300,12 @@ Take the following example function:
300
300
entry:
301
301
br label %loop
302
302
303
- loop:
303
+ loop:
304
304
%i = phi i32 [ 0, %entry ], [ %i2, %loop.end ]
305
305
%cond = icmp ule i32 %i, %n
306
306
br i1 %cond, label %loop.cont, label %exit
307
307
308
- loop.cont:
308
+ loop.cont:
309
309
br i1 %c, label %then, label %else
310
310
311
311
then:
@@ -334,22 +334,22 @@ We would obtain the following IR:
334
334
entry:
335
335
br i1 %c, label %then, label %else
336
336
337
- then:
337
+ then:
338
338
%i = phi i32 [ 0, %entry ], [ %i2, %then.cont ]
339
339
%cond = icmp ule i32 %i, %n
340
340
br i1 %cond, label %then.cont, label %exit
341
341
342
- then.cont:
342
+ then.cont:
343
343
...
344
344
%i2 = add i32 %i, 1
345
345
br label %then
346
346
347
- else:
347
+ else:
348
348
%i3 = phi i32 [ 0, %entry ], [ %i4, %else.cont ]
349
349
%cond = icmp ule i32 %i3, %n
350
350
br i1 %cond, label %else.cont, label %exit
351
351
352
- else.cont:
352
+ else.cont:
353
353
...
354
354
%i4 = add i32 %i3, 1
355
355
br label %else
@@ -381,6 +381,8 @@ We can make the loop unswitching optimization above correct as follows:
381
381
entry:
382
382
%c2 = freeze i1 %c
383
383
br i1 %c2, label %then, label %else
384
+ ...
385
+ }
384
386
385
387
386
388
Writing Tests Without Undefined Behavior
@@ -399,7 +401,7 @@ particular divisor value because our optimization kicks in regardless:
399
401
define i32 @fn(i8 %a) {
400
402
%div = udiv i8 %a, poison
401
403
...
402
- }
404
+ }
403
405
404
406
The issue with this test is that it triggers immediate UB. This prevents
405
407
verification tools like Alive from validating the correctness of the
@@ -412,7 +414,7 @@ The test above should use a dummy function argument instead of using poison:
412
414
define i32 @fn(i8 %a, i8 %dummy) {
413
415
%div = udiv i8 %a, %dummy
414
416
...
415
- }
417
+ }
416
418
417
419
Common sources of immediate UB in tests include branching on undef/poison
418
420
conditions and dereferencing undef/poison/null pointers.
0 commit comments