OLD | NEW |
(Empty) | |
| 1 ; RUN: opt < %s -expand-constant-expr -S | FileCheck %s |
| 2 |
| 3 @global_var1 = global i32 123 |
| 4 @global_var2 = global i32 123 |
| 5 |
| 6 |
| 7 define i8* @constantexpr_bitcast() { |
| 8 ret i8* bitcast (i32* @global_var1 to i8*) |
| 9 } |
| 10 ; CHECK: @constantexpr_bitcast() |
| 11 ; CHECK: %expanded = bitcast i32* @global_var1 to i8* |
| 12 ; CHECK: ret i8* %expanded |
| 13 |
| 14 |
| 15 define i32 @constantexpr_nested() { |
| 16 ret i32 add (i32 ptrtoint (i32* @global_var1 to i32), |
| 17 i32 ptrtoint (i32* @global_var2 to i32)) |
| 18 } |
| 19 ; CHECK: @constantexpr_nested |
| 20 ; CHECK: %expanded1 = ptrtoint i32* @global_var1 to i32 |
| 21 ; CHECK: %expanded2 = ptrtoint i32* @global_var2 to i32 |
| 22 ; CHECK: %expanded = add i32 %expanded1, %expanded2 |
| 23 ; CHECK: ret i32 %expanded |
| 24 |
| 25 |
| 26 define i32 @constantexpr_phi() { |
| 27 entry: |
| 28 br label %label |
| 29 label: |
| 30 %result = phi i32 [ ptrtoint (i32* @global_var1 to i32), %entry ] |
| 31 ret i32 %result |
| 32 } |
| 33 ; CHECK: @constantexpr_phi |
| 34 ; CHECK: entry: |
| 35 ; CHECK: %expanded = ptrtoint i32* @global_var1 to i32 |
| 36 ; CHECK: br label %label |
| 37 ; CHECK: label: |
| 38 ; CHECK: %result = phi i32 [ %expanded, %entry ] |
| 39 |
| 40 |
| 41 ; This tests that ExpandConstantExpr correctly handles a PHI node that |
| 42 ; contains the same ConstantExpr twice. |
| 43 ; Using replaceAllUsesWith() is not correct on a PHI node when the |
| 44 ; new instruction has to be added to an incoming block. |
| 45 define i32 @constantexpr_phi_twice(i1 %arg) { |
| 46 entry: |
| 47 br i1 %arg, label %iftrue, label %iffalse |
| 48 iftrue: |
| 49 br label %exit |
| 50 iffalse: |
| 51 br label %exit |
| 52 exit: |
| 53 %result = phi i32 [ ptrtoint (i32* @global_var1 to i32), %iftrue ], |
| 54 [ ptrtoint (i32* @global_var1 to i32), %iffalse ] |
| 55 ret i32 %result |
| 56 } |
| 57 ; CHECK: @constantexpr_phi_twice |
| 58 ; CHECK: iftrue: |
| 59 ; CHECK: %expanded = ptrtoint i32* @global_var1 to i32 |
| 60 ; CHECK: iffalse: |
| 61 ; CHECK: %expanded1 = ptrtoint i32* @global_var1 to i32 |
| 62 ; CHECK: exit: |
OLD | NEW |