[llvm] r267082 - [WebAssembly] Limit alignment hints to natural alignment.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 16:59:48 PDT 2016
Author: djg
Date: Thu Apr 21 18:59:48 2016
New Revision: 267082
URL: http://llvm.org/viewvc/llvm-project?rev=267082&view=rev
Log:
[WebAssembly] Limit alignment hints to natural alignment.
This follows the current binary format rules.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
llvm/trunk/test/CodeGen/WebAssembly/byval.ll
llvm/trunk/test/CodeGen/WebAssembly/i32-load-store-alignment.ll
llvm/trunk/test/CodeGen/WebAssembly/i64-load-store-alignment.ll
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp?rev=267082&r1=267081&r2=267082&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp Thu Apr 21 18:59:48 2016
@@ -83,7 +83,7 @@ bool WebAssemblySetP2AlignOperands::runO
case WebAssembly::STORE16_I32:
case WebAssembly::STORE8_I64:
case WebAssembly::STORE16_I64:
- case WebAssembly::STORE32_I64:
+ case WebAssembly::STORE32_I64: {
assert(MI.getOperand(3).getImm() == 0 &&
"ISel should set p2align operands to 0");
assert(MI.hasOneMemOperand() &&
@@ -95,9 +95,15 @@ bool WebAssemblySetP2AlignOperands::runO
assert(MI.getDesc().OpInfo[3].OperandType ==
WebAssembly::OPERAND_P2ALIGN &&
"Load and store instructions should have a p2align operand");
- MI.getOperand(3).setImm(
- Log2_64((*MI.memoperands_begin())->getAlignment()));
+ uint64_t P2Align = Log2_64((*MI.memoperands_begin())->getAlignment());
+
+ // WebAssembly does not currently support supernatural alignment.
+ P2Align = std::min(
+ P2Align, uint64_t(WebAssembly::GetDefaultP2Align(MI.getOpcode())));
+
+ MI.getOperand(3).setImm(P2Align);
break;
+ }
default:
break;
}
Modified: llvm/trunk/test/CodeGen/WebAssembly/byval.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/byval.ll?rev=267082&r1=267081&r2=267082&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/byval.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/byval.ll Thu Apr 21 18:59:48 2016
@@ -55,8 +55,8 @@ define void @byval_arg_align8(%SmallStru
; CHECK: i32.const $push[[L1:.+]]=, 16
; CHECK-NEXT: i32.sub [[SP:.+]]=, {{.+}}, $pop[[L1]]
; Copy the SmallStruct argument to the stack (SP+8, original SP-8)
- ; CHECK: i32.load $push[[L4:.+]]=, 0($0):p2align=3
- ; CHECK-NEXT: i32.store {{.*}}=, 8([[SP]]):p2align=3, $pop[[L4]]
+ ; CHECK: i32.load $push[[L4:.+]]=, 0($0){{$}}
+ ; CHECK-NEXT: i32.store {{.*}}=, 8([[SP]]), $pop[[L4]]{{$}}
; Pass a pointer to the stack slot to the function
; CHECK-NEXT: i32.const $push[[L5:.+]]=, 8
; CHECK-NEXT: i32.add $push[[ARG:.+]]=, [[SP]], $pop[[L5]]
Modified: llvm/trunk/test/CodeGen/WebAssembly/i32-load-store-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/i32-load-store-alignment.ll?rev=267082&r1=267081&r2=267082&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/i32-load-store-alignment.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/i32-load-store-alignment.ll Thu Apr 21 18:59:48 2016
@@ -49,10 +49,12 @@ define i32 @ldi32(i32 *%p) {
ret i32 %v
}
+; 8 is greater than the default alignment so it is ignored.
+
; CHECK-LABEL: ldi32_a8:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i32{{$}}
-; CHECK-NEXT: i32.load $push[[NUM:[0-9]+]]=, 0($0):p2align=3{{$}}
+; CHECK-NEXT: i32.load $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i32 @ldi32_a8(i32 *%p) {
%v = load i32, i32* %p, align 8
@@ -74,7 +76,7 @@ define i8 @ldi8_a1(i8 *%p) {
; CHECK-LABEL: ldi8_a2:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i32{{$}}
-; CHECK-NEXT: i32.load8_u $push[[NUM:[0-9]+]]=, 0($0):p2align=1{{$}}
+; CHECK-NEXT: i32.load8_u $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i8 @ldi8_a2(i8 *%p) {
%v = load i8, i8* %p, align 2
@@ -104,7 +106,7 @@ define i16 @ldi16_a2(i16 *%p) {
; CHECK-LABEL: ldi16_a4:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i32{{$}}
-; CHECK-NEXT: i32.load16_u $push[[NUM:[0-9]+]]=, 0($0):p2align=2{{$}}
+; CHECK-NEXT: i32.load16_u $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i16 @ldi16_a4(i16 *%p) {
%v = load i16, i16* %p, align 4
@@ -155,7 +157,7 @@ define void @sti32(i32 *%p, i32 %v) {
; CHECK-LABEL: sti32_a8:
; CHECK-NEXT: .param i32, i32{{$}}
-; CHECK-NEXT: i32.store $discard=, 0($0):p2align=3, $1{{$}}
+; CHECK-NEXT: i32.store $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti32_a8(i32 *%p, i32 %v) {
store i32 %v, i32* %p, align 8
@@ -175,7 +177,7 @@ define void @sti8_a1(i8 *%p, i8 %v) {
; CHECK-LABEL: sti8_a2:
; CHECK-NEXT: .param i32, i32{{$}}
-; CHECK-NEXT: i32.store8 $discard=, 0($0):p2align=1, $1{{$}}
+; CHECK-NEXT: i32.store8 $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti8_a2(i8 *%p, i8 %v) {
store i8 %v, i8* %p, align 2
@@ -202,7 +204,7 @@ define void @sti16_a2(i16 *%p, i16 %v) {
; CHECK-LABEL: sti16_a4:
; CHECK-NEXT: .param i32, i32{{$}}
-; CHECK-NEXT: i32.store16 $discard=, 0($0):p2align=2, $1{{$}}
+; CHECK-NEXT: i32.store16 $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti16_a4(i16 *%p, i16 %v) {
store i16 %v, i16* %p, align 4
Modified: llvm/trunk/test/CodeGen/WebAssembly/i64-load-store-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/i64-load-store-alignment.ll?rev=267082&r1=267081&r2=267082&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/i64-load-store-alignment.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/i64-load-store-alignment.ll Thu Apr 21 18:59:48 2016
@@ -35,7 +35,7 @@ define i64 @ldi64_a4(i64 *%p) {
ret i64 %v
}
-; 8 is the default alignment for i32 so no attribute is needed.
+; 8 is the default alignment for i64 so no attribute is needed.
; CHECK-LABEL: ldi64_a8:
; CHECK-NEXT: .param i32{{$}}
@@ -59,10 +59,12 @@ define i64 @ldi64(i64 *%p) {
ret i64 %v
}
+; 16 is greater than the default alignment so it is ignored.
+
; CHECK-LABEL: ldi64_a16:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i64{{$}}
-; CHECK-NEXT: i64.load $push[[NUM:[0-9]+]]=, 0($0):p2align=4{{$}}
+; CHECK-NEXT: i64.load $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @ldi64_a16(i64 *%p) {
%v = load i64, i64* %p, align 16
@@ -85,7 +87,7 @@ define i64 @ldi8_a1(i8 *%p) {
; CHECK-LABEL: ldi8_a2:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i64{{$}}
-; CHECK-NEXT: i64.load8_u $push[[NUM:[0-9]+]]=, 0($0):p2align=1{{$}}
+; CHECK-NEXT: i64.load8_u $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @ldi8_a2(i8 *%p) {
%v = load i8, i8* %p, align 2
@@ -118,7 +120,7 @@ define i64 @ldi16_a2(i16 *%p) {
; CHECK-LABEL: ldi16_a4:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i64{{$}}
-; CHECK-NEXT: i64.load16_u $push[[NUM:[0-9]+]]=, 0($0):p2align=2{{$}}
+; CHECK-NEXT: i64.load16_u $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @ldi16_a4(i16 *%p) {
%v = load i16, i16* %p, align 4
@@ -162,7 +164,7 @@ define i64 @ldi32_a4(i32 *%p) {
; CHECK-LABEL: ldi32_a8:
; CHECK-NEXT: .param i32{{$}}
; CHECK-NEXT: .result i64{{$}}
-; CHECK-NEXT: i64.load32_u $push[[NUM:[0-9]+]]=, 0($0):p2align=3{{$}}
+; CHECK-NEXT: i64.load32_u $push[[NUM:[0-9]+]]=, 0($0){{$}}
; CHECK-NEXT: return $pop[[NUM]]{{$}}
define i64 @ldi32_a8(i32 *%p) {
%v = load i32, i32* %p, align 8
@@ -223,7 +225,7 @@ define void @sti64(i64 *%p, i64 %v) {
; CHECK-LABEL: sti64_a16:
; CHECK-NEXT: .param i32, i64{{$}}
-; CHECK-NEXT: i64.store $discard=, 0($0):p2align=4, $1{{$}}
+; CHECK-NEXT: i64.store $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti64_a16(i64 *%p, i64 %v) {
store i64 %v, i64* %p, align 16
@@ -244,7 +246,7 @@ define void @sti8_a1(i8 *%p, i64 %w) {
; CHECK-LABEL: sti8_a2:
; CHECK-NEXT: .param i32, i64{{$}}
-; CHECK-NEXT: i64.store8 $discard=, 0($0):p2align=1, $1{{$}}
+; CHECK-NEXT: i64.store8 $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti8_a2(i8 *%p, i64 %w) {
%v = trunc i64 %w to i8
@@ -274,7 +276,7 @@ define void @sti16_a2(i16 *%p, i64 %w) {
; CHECK-LABEL: sti16_a4:
; CHECK-NEXT: .param i32, i64{{$}}
-; CHECK-NEXT: i64.store16 $discard=, 0($0):p2align=2, $1{{$}}
+; CHECK-NEXT: i64.store16 $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti16_a4(i16 *%p, i64 %w) {
%v = trunc i64 %w to i16
@@ -314,7 +316,7 @@ define void @sti32_a4(i32 *%p, i64 %w) {
; CHECK-LABEL: sti32_a8:
; CHECK-NEXT: .param i32, i64{{$}}
-; CHECK-NEXT: i64.store32 $discard=, 0($0):p2align=3, $1{{$}}
+; CHECK-NEXT: i64.store32 $discard=, 0($0), $1{{$}}
; CHECK-NEXT: return{{$}}
define void @sti32_a8(i32 *%p, i64 %w) {
%v = trunc i64 %w to i32
More information about the llvm-commits
mailing list