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

Perform with.overflow expansion before struct reg expansion #258

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Target/JSBackend/JSBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,10 @@ bool JSTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream
// function arguments and returns into something ExpandStructRegs can expand.
PM.add(createSimplifyStructRegSignaturesPass());

// ExpandStructRegs must be run after ExpandArithWithOverflow to expand out
// the insertvalue instructions that ExpandArithWithOverflow introduces.
PM.add(createExpandArithWithOverflowPass());

// TODO(mtrofin) Remove the following and only run it as a post-opt pass once
// the following bug is fixed.
// https://code.google.com/p/nativeclient/issues/detail?id=3857
Expand All @@ -4785,10 +4789,6 @@ bool JSTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream
if (EnableEmAsyncify)
PM.add(createLowerEmAsyncifyPass());

// ExpandStructRegs must be run after ExpandArithWithOverflow to expand out
// the insertvalue instructions that ExpandArithWithOverflow introduces.
PM.add(createExpandArithWithOverflowPass());

// We place ExpandByVal after optimization passes because some byval
// arguments can be expanded away by the ArgPromotion pass. Leaving
// in "byval" during optimization also allows some dead stores to be
Expand Down
19 changes: 19 additions & 0 deletions test/CodeGen/JS/with-overflow.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; RUN: llc < %s | FileCheck %s

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"
target triple = "asmjs-unknown-emscripten"

declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32)

; CHECK-LABEL: function _test($x)
; CHECK-NEXT: $x = $x|0;
; CHECK-NEXT: var $a$arith = 0, label = 0, sp = 0;
; CHECK-NEXT: sp = STACKTOP;
; CHECK-NEXT: $a$arith = (($x) + 1)|0;
; CHECK-NEXT: return ($a$arith|0);
define i32 @test(i32 %x) {
%a = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %x, i32 1)
%b = insertvalue { i32, i1 } %a, i1 false, 1
%c = extractvalue { i32, i1 } %b, 0
ret i32 %c
}