Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 94f5a3e

Browse files
nikickripken
authored andcommitted
Perform with.overflow expansion befor struct reg expansion (#258)
Make sure ExpandArithWithOverflow runs before ExpandStructRegs. While the latter has a check to avoid processing struct returns of intrinsics, it only works when directly extracting from one. In rust-lang/rust#58623 we ran into a case where an extractvalue of an insertvalue of a with.overflow intrinsic is performed, as shown in the test case.
1 parent ae66526 commit 94f5a3e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/Target/JSBackend/JSBackend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,10 @@ bool JSTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream
47754775
// function arguments and returns into something ExpandStructRegs can expand.
47764776
PM.add(createSimplifyStructRegSignaturesPass());
47774777

4778+
// ExpandStructRegs must be run after ExpandArithWithOverflow to expand out
4779+
// the insertvalue instructions that ExpandArithWithOverflow introduces.
4780+
PM.add(createExpandArithWithOverflowPass());
4781+
47784782
// TODO(mtrofin) Remove the following and only run it as a post-opt pass once
47794783
// the following bug is fixed.
47804784
// https://code.google.com/p/nativeclient/issues/detail?id=3857
@@ -4785,10 +4789,6 @@ bool JSTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream
47854789
if (EnableEmAsyncify)
47864790
PM.add(createLowerEmAsyncifyPass());
47874791

4788-
// ExpandStructRegs must be run after ExpandArithWithOverflow to expand out
4789-
// the insertvalue instructions that ExpandArithWithOverflow introduces.
4790-
PM.add(createExpandArithWithOverflowPass());
4791-
47924792
// We place ExpandByVal after optimization passes because some byval
47934793
// arguments can be expanded away by the ArgPromotion pass. Leaving
47944794
// in "byval" during optimization also allows some dead stores to be

test/CodeGen/JS/with-overflow.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
target datalayout = "e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-p:32:32:32-v128:32:128-n32-S128"
4+
target triple = "asmjs-unknown-emscripten"
5+
6+
declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32)
7+
8+
; CHECK-LABEL: function _test($x)
9+
; CHECK-NEXT: $x = $x|0;
10+
; CHECK-NEXT: var $a$arith = 0, label = 0, sp = 0;
11+
; CHECK-NEXT: sp = STACKTOP;
12+
; CHECK-NEXT: $a$arith = (($x) + 1)|0;
13+
; CHECK-NEXT: return ($a$arith|0);
14+
define i32 @test(i32 %x) {
15+
%a = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 1)
16+
%b = insertvalue { i32, i1 } %a, i1 false, 1
17+
%c = extractvalue { i32, i1 } %b, 0
18+
ret i32 %c
19+
}

0 commit comments

Comments
 (0)