Commit d418f68d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix one more 32 bit 64 bit promotion

And add a helper method to convert an uint32 value to uintptr (e.g. a
noop on 32 bit and Uint32ToUint64 conversion on 64 bit).

R=ahaas@chromium.org

Change-Id: Ibc6731bc7ddaf8ceaa27e9e8fbec916d184d9ad4
Reviewed-on: https://chromium-review.googlesource.com/836618
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50246}
parent 17f3fe94
...@@ -2712,12 +2712,8 @@ Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { ...@@ -2712,12 +2712,8 @@ Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) {
} }
Node* WasmGraphBuilder::BuildChangeUint32ToSmi(Node* value) { Node* WasmGraphBuilder::BuildChangeUint32ToSmi(Node* value) {
if (jsgraph()->machine()->Is64()) { return graph()->NewNode(jsgraph()->machine()->WordShl(),
value = Uint32ToUintptr(value), BuildSmiShiftBitsConstant());
graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), value);
}
return graph()->NewNode(jsgraph()->machine()->WordShl(), value,
BuildSmiShiftBitsConstant());
} }
Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) { Node* WasmGraphBuilder::BuildChangeSmiToFloat64(Node* value) {
...@@ -3497,7 +3493,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index, ...@@ -3497,7 +3493,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
uint32_t offset, uint32_t offset,
wasm::WasmCodePosition position, wasm::WasmCodePosition position,
EnforceBoundsCheck enforce_check) { EnforceBoundsCheck enforce_check) {
if (FLAG_wasm_no_bounds_checks) return index; if (FLAG_wasm_no_bounds_checks) return Uint32ToUintptr(index);
DCHECK_NOT_NULL(context_cache_); DCHECK_NOT_NULL(context_cache_);
Node* mem_size = context_cache_->mem_size; Node* mem_size = context_cache_->mem_size;
Node* mem_mask = context_cache_->mem_mask; Node* mem_mask = context_cache_->mem_mask;
...@@ -3508,8 +3504,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index, ...@@ -3508,8 +3504,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
if (use_trap_handler() && enforce_check == kCanOmitBoundsCheck) { if (use_trap_handler() && enforce_check == kCanOmitBoundsCheck) {
// Simply zero out the 32-bits on 64-bit targets and let the trap handler // Simply zero out the 32-bits on 64-bit targets and let the trap handler
// do its job. // do its job.
return m->Is64() ? graph()->NewNode(m->ChangeUint32ToUint64(), index) return Uint32ToUintptr(index);
: index;
} }
uint32_t min_size = env_->module->initial_pages * wasm::WasmModule::kPageSize; uint32_t min_size = env_->module->initial_pages * wasm::WasmModule::kPageSize;
...@@ -3549,8 +3544,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index, ...@@ -3549,8 +3544,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
if ((index_val + offset + access_size) <= min_size) { if ((index_val + offset + access_size) <= min_size) {
// The input index is a constant and everything is statically within // The input index is a constant and everything is statically within
// bounds of the smallest possible memory. // bounds of the smallest possible memory.
return m->Is64() ? graph()->NewNode(m->ChangeUint32ToUint64(), index) return Uint32ToUintptr(index);
: index;
} }
} }
} }
...@@ -3575,8 +3569,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index, ...@@ -3575,8 +3569,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
// In the fallthrough case, condition the index with the memory mask. // In the fallthrough case, condition the index with the memory mask.
Node* masked_index = graph()->NewNode(m->Word32And(), index, mem_mask); Node* masked_index = graph()->NewNode(m->Word32And(), index, mem_mask);
return m->Is64() ? graph()->NewNode(m->ChangeUint32ToUint64(), masked_index) return Uint32ToUintptr(masked_index);
: masked_index;
} }
const Operator* WasmGraphBuilder::GetSafeLoadOperator(int offset, const Operator* WasmGraphBuilder::GetSafeLoadOperator(int offset,
...@@ -3765,10 +3758,7 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) { ...@@ -3765,10 +3758,7 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) {
// Condition the index with the memory mask. // Condition the index with the memory mask.
index = graph()->NewNode(jsgraph()->machine()->Word32And(), index, mem_mask); index = graph()->NewNode(jsgraph()->machine()->Word32And(), index, mem_mask);
if (jsgraph()->machine()->Is64()) { index = Uint32ToUintptr(index);
index =
graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), index);
}
Node* load = graph()->NewNode(jsgraph()->machine()->Load(type), mem_start, Node* load = graph()->NewNode(jsgraph()->machine()->Load(type), mem_start,
index, *effect_, bounds_check.if_true); index, *effect_, bounds_check.if_true);
Node* value_phi = Node* value_phi =
...@@ -3781,6 +3771,11 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) { ...@@ -3781,6 +3771,11 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) {
return value_phi; return value_phi;
} }
Node* WasmGraphBuilder::Uint32ToUintptr(Node* node) {
if (jsgraph()->machine()->Is32()) return node;
return graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), node);
}
Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index, Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index,
Node* val) { Node* val) {
DCHECK_NOT_NULL(context_cache_); DCHECK_NOT_NULL(context_cache_);
...@@ -3804,10 +3799,7 @@ Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index, ...@@ -3804,10 +3799,7 @@ Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index,
// Condition the index with the memory mask. // Condition the index with the memory mask.
index = graph()->NewNode(jsgraph()->machine()->Word32And(), index, mem_mask); index = graph()->NewNode(jsgraph()->machine()->Word32And(), index, mem_mask);
if (jsgraph()->machine()->Is64()) { index = Uint32ToUintptr(index);
index =
graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), index);
}
const Operator* store_op = jsgraph()->machine()->Store(StoreRepresentation( const Operator* store_op = jsgraph()->machine()->Store(StoreRepresentation(
type.representation(), WriteBarrierKind::kNoWriteBarrier)); type.representation(), WriteBarrierKind::kNoWriteBarrier));
Node* store = graph()->NewNode(store_op, mem_start, index, val, *effect_, Node* store = graph()->NewNode(store_op, mem_start, index, val, *effect_,
......
...@@ -462,6 +462,7 @@ class WasmGraphBuilder { ...@@ -462,6 +462,7 @@ class WasmGraphBuilder {
// BoundsCheckMem receives a uint32 {index} node and returns a ptrsize index. // BoundsCheckMem receives a uint32 {index} node and returns a ptrsize index.
Node* BoundsCheckMem(uint8_t access_size, Node* index, uint32_t offset, Node* BoundsCheckMem(uint8_t access_size, Node* index, uint32_t offset,
wasm::WasmCodePosition, EnforceBoundsCheck); wasm::WasmCodePosition, EnforceBoundsCheck);
Node* Uint32ToUintptr(Node*);
const Operator* GetSafeLoadOperator(int offset, wasm::ValueType type); const Operator* GetSafeLoadOperator(int offset, wasm::ValueType type);
const Operator* GetSafeStoreOperator(int offset, wasm::ValueType type); const Operator* GetSafeStoreOperator(int offset, wasm::ValueType type);
Node* BuildChangeEndiannessStore(Node* node, MachineRepresentation rep, Node* BuildChangeEndiannessStore(Node* node, MachineRepresentation rep,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment