| Chris Lattner | 593a74a | 2002-08-12 19:18:49 +0000 | [diff] [blame] | 1 | ; I'm not really sure if instcombine should do things like these. LevelRaise |
| 2 | ; already sufficiently takes care of these cases, but level raise is really |
| 3 | ; slow. Might it be better to make there be an instcombine prepass before |
| 4 | ; level raise that takes care of the obvious stuff? |
| 5 | |
| Misha Brukman | edf4bab | 2003-09-16 15:29:54 +0000 | [diff] [blame] | 6 | ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep cast |
| Chris Lattner | 4b474fc56 | 2002-05-15 17:22:01 +0000 | [diff] [blame] | 7 | |
| Chris Lattner | 4a16110 | 2002-08-15 19:38:03 +0000 | [diff] [blame] | 8 | bool %test1(int %X) { |
| Chris Lattner | 4b474fc56 | 2002-05-15 17:22:01 +0000 | [diff] [blame] | 9 | %A = cast int %X to uint |
| Chris Lattner | 14f7522 | 2003-07-23 23:21:08 +0000 | [diff] [blame] | 10 | %c = setne uint %A, 12 ; Convert to setne int %X, 12 |
| Chris Lattner | 4b474fc56 | 2002-05-15 17:22:01 +0000 | [diff] [blame] | 11 | ret bool %c |
| 12 | } |
| 13 | |
| Chris Lattner | 4a16110 | 2002-08-15 19:38:03 +0000 | [diff] [blame] | 14 | bool %test2(int %X, int %Y) { |
| Chris Lattner | 4b474fc56 | 2002-05-15 17:22:01 +0000 | [diff] [blame] | 15 | %A = cast int %X to uint |
| 16 | %B = cast int %Y to uint |
| 17 | %c = setne uint %A, %B ; Convert to setne int %X, %Y |
| 18 | ret bool %c |
| 19 | } |
| 20 | |
| Chris Lattner | 4a16110 | 2002-08-15 19:38:03 +0000 | [diff] [blame] | 21 | bool %test3(int %A, int %B) { |
| 22 | %cond216 = setlt int %A, %B ; <bool> [#uses=1] |
| 23 | %cst109 = cast bool %cond216 to uint ; <uint> [#uses=1] |
| 24 | %cond219 = setgt int %A, %B ; <bool> [#uses=1] |
| 25 | %cst111 = cast bool %cond219 to uint ; <uint> [#uses=1] |
| 26 | %reg113 = and uint %cst109, %cst111 ; <uint> [#uses=1] |
| 27 | %cst222 = cast uint %reg113 to bool ; <int> [#uses=1] |
| 28 | ret bool %cst222 |
| 29 | } |
| 30 | |
| Chris Lattner | 1d48528 | 2003-03-05 22:50:55 +0000 | [diff] [blame] | 31 | int %test4(int %A) { |
| 32 | %B = cast int %A to uint |
| Chris Lattner | 14f7522 | 2003-07-23 23:21:08 +0000 | [diff] [blame] | 33 | %C = shl uint %B, ubyte 2 |
| Chris Lattner | 1d48528 | 2003-03-05 22:50:55 +0000 | [diff] [blame] | 34 | %D = cast uint %C to int |
| 35 | ret int %D |
| 36 | } |
| 37 | |
| Chris Lattner | 14f7522 | 2003-07-23 23:21:08 +0000 | [diff] [blame] | 38 | short %test5(short %A) { |
| 39 | %B = cast short %A to uint |
| 40 | %C = and uint %B, 15 |
| 41 | %D = cast uint %C to short |
| 42 | ret short %D |
| 43 | } |
| Chris Lattner | c75cfac | 2003-11-03 03:51:26 +0000 | [diff] [blame] | 44 | |
| 45 | bool %test6(bool %A) { |
| 46 | %B = cast bool %A to int |
| 47 | %C = setne int %B, 0 |
| 48 | ret bool %C |
| 49 | } |
| Chris Lattner | efde768 | 2003-11-03 03:52:34 +0000 | [diff] [blame] | 50 | |
| Chris Lattner | 11bea4f | 2003-11-03 05:08:53 +0000 | [diff] [blame^] | 51 | bool %test6a(bool %A) { |
| 52 | %B = cast bool %A to int |
| 53 | %C = setne int %B, -1 ; Always true! |
| 54 | ret bool %C |
| 55 | } |
| 56 | |
| Chris Lattner | efde768 | 2003-11-03 03:52:34 +0000 | [diff] [blame] | 57 | bool %test7(sbyte* %A) { |
| 58 | %B = cast sbyte* %A to int* |
| 59 | %C = seteq int* %B, null |
| 60 | ret bool %C |
| 61 | } |