@@ -16,7 +16,9 @@ We also provide guidelines on when to use each form of UB.
1616Introduction
1717============
1818Undefined behavior is used to specify the behavior of corner cases for which we
19- don't wish to specify the concrete results.
19+ don't wish to specify the concrete results. UB is also used to provide
20+ additional constraints to the optimizers (e.g., assumptions that the frontend
21+ guarantees through the language type system or the runtime).
2022For example, we could specify the result of division by zero as zero, but
2123since we are not really interested in the result, we say it is UB.
2224
@@ -309,11 +311,9 @@ We can make the loop unswitching optimization above correct as follows:
309311 br i1 %c2, label %then, label %else
310312
311313
312- Writing Tests
313- =============
314+ Writing Tests that Avoid UB
315+ ===========================
314316
315- Avoiding UB
316- -----------
317317When writing tests, it is important to ensure that they don't trigger UB
318318unnecessarily. Some automated test reduces sometimes use undef or poison
319319values as dummy values, but this is considered a bad practice if this leads
@@ -349,20 +349,3 @@ conditions and dereferencing undef/poison/null pointers.
349349 If you need a placeholder value to pass as an argument to an instruction
350350 that may trigger UB, add a new argument to the function rather than using
351351 undef or poison.
352-
353-
354- Reducing bitwidth
355- -----------------
356- To speed up automated verification of tests (e.g., using Alive), it is
357- recommended that tests use low bitwidth formats and small vector sizes.
358- For example, if we write a test to check that a multiplication by two is
359- replaced by a shift left, we can do so using 8-bit integers instead of the
360- usual 32-bit integers:
361-
362- .. code-block :: llvm
363-
364- define i8 @fn(i8 %val) {
365- ; CHECK: %mul2 = shl %val, 1
366- %mul2 = mul i8 %val, 2
367- ret i8 %mul2
368- }
0 commit comments