|
80 | 80 | ; constants are zero extended for phi incoming values so an AssertZExt is
|
81 | 81 | ; created in 'merge' allowing the zext to be removed.
|
82 | 82 | ; SelectionDAG::getNode treats any_extend of i32 constants as sext for RISCV.
|
83 |
| -; The code that creates phi incoming values in the predecessors creates an |
84 |
| -; any_extend for the constants which then gets treated as a sext by getNode. |
85 |
| -; This means the zext was not safe to remove. |
| 83 | +; This code used to miscompile because the code that creates phi incoming values |
| 84 | +; in the predecessors created any_extend for the constants which then gets |
| 85 | +; treated as a sext by getNode. This made the removal of the zext incorrect. |
| 86 | +; SelectionDAGBuilder now creates a zero_extend instead of an any_extend to |
| 87 | +; match the assumption. |
| 88 | +; FIXME: RISCV would prefer constant inputs to phis to be sign extended. |
86 | 89 | define i64 @miscompile(i32 %c) {
|
87 | 90 | ; RV64I-LABEL: miscompile:
|
88 | 91 | ; RV64I: # %bb.0:
|
89 |
| -; RV64I-NEXT: sext.w a1, a0 |
| 92 | +; RV64I-NEXT: sext.w a0, a0 |
| 93 | +; RV64I-NEXT: beqz a0, .LBB2_2 |
| 94 | +; RV64I-NEXT: # %bb.1: |
90 | 95 | ; RV64I-NEXT: li a0, -1
|
91 |
| -; RV64I-NEXT: beqz a1, .LBB2_2 |
92 |
| -; RV64I-NEXT: # %bb.1: # %merge |
| 96 | +; RV64I-NEXT: srli a0, a0, 32 |
93 | 97 | ; RV64I-NEXT: ret
|
94 | 98 | ; RV64I-NEXT: .LBB2_2: # %iffalse
|
95 |
| -; RV64I-NEXT: li a0, -2 |
| 99 | +; RV64I-NEXT: li a0, 1 |
| 100 | +; RV64I-NEXT: slli a0, a0, 32 |
| 101 | +; RV64I-NEXT: addi a0, a0, -2 |
96 | 102 | ; RV64I-NEXT: ret
|
97 | 103 | %a = icmp ne i32 %c, 0
|
98 | 104 | br i1 %a, label %iftrue, label %iffalse
|
|
0 commit comments