Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 1 | /* Check that the result of a bitfield assignment is properly |
| 2 | truncated and does not generate a redundant load. */ |
| 3 | |
| 4 | /* Check that we get one load for each simple assign and two for the |
| 5 | compound assign (load the old value before the add then load again |
| 6 | to store back). Also check that our g0 pattern is good. */ |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 7 | // RUN: clang-cc -triple i386-unknown-unknown -O0 -emit-llvm -o %t %s |
| 8 | // RUN: grep 'load ' %t | count 5 |
| 9 | // RUN: grep "@g0" %t | count 4 |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 10 | |
| 11 | // Check that we got the right value. |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 12 | // RUN: clang-cc -triple i386-unknown-unknown -O3 -emit-llvm -o %t %s |
| 13 | // RUN: grep 'load ' %t | count 0 |
Daniel Dunbar | ed3849b | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 14 | // RUN: grep "@g0" %t | count 0 |
| 15 | |
| 16 | struct s0 { |
| 17 | int f0 : 2; |
| 18 | _Bool f1 : 1; |
| 19 | unsigned f2 : 2; |
| 20 | }; |
| 21 | |
| 22 | int g0(); |
| 23 | |
| 24 | void f0(void) { |
| 25 | struct s0 s; |
| 26 | if ((s.f0 = 3) != -1) g0(); |
| 27 | } |
| 28 | |
| 29 | void f1(void) { |
| 30 | struct s0 s; |
| 31 | if ((s.f1 = 3) != 1) g0(); |
| 32 | } |
| 33 | |
| 34 | void f2(void) { |
| 35 | struct s0 s; |
| 36 | if ((s.f2 = 3) != 3) g0(); |
| 37 | } |
| 38 | |
| 39 | void f3(void) { |
| 40 | struct s0 s; |
| 41 | // Just check this one for load counts. |
| 42 | s.f0 += 3; |
| 43 | } |
| 44 | |