Skip to content

Commit

Permalink
fallback: alloca alignments update
Browse files Browse the repository at this point in the history
  • Loading branch information
swfly committed Nov 28, 2024
1 parent f05d9ac commit b683555
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/backends/fallback/fallback_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ class FallbackCodegen {
4u, false);
// Allocate space for the result locally
auto result_alloca = b.CreateAlloca(outType, nullptr, "");
result_alloca->setAlignment(llvm::Align(inst->type()->alignment()));

// Extract x and y from uint2 coordinate
auto coord_x = b.CreateExtractElement(llvm_coord, b.getInt32(0), "");
Expand Down Expand Up @@ -1445,6 +1446,7 @@ class FallbackCodegen {
4u, false);
// Allocate space for the result locally
auto result_alloca = b.CreateAlloca(outType, nullptr, "");
result_alloca->setAlignment(llvm::Align(inst->type()->alignment()));

// Extract x and y from uint2 coordinate
auto coord_x = b.CreateExtractElement(llvm_coord, b.getInt32(0), "");
Expand Down Expand Up @@ -1667,6 +1669,7 @@ class FallbackCodegen {
auto llvm_value_type = _translate_type(inst->type(), true);
// Allocate space for the texture view struct
auto val_alloca = b.CreateAlloca(llvm_value_type, nullptr, "");
val_alloca->setAlignment(llvm::Align(alignment));


// Define the function type: void(void*, uint, uint, void*)
Expand All @@ -1685,7 +1688,7 @@ class FallbackCodegen {
// Call the function
b.CreateCall(func, {llvm_bindless, llvm_slot, llvm_elem, llvm_data_stride, val_alloca});
// Return the loaded result
return b.CreateLoad(llvm_value_type, val_alloca, "");
return b.CreateAlignedLoad(llvm_value_type, val_alloca, llvm::MaybeAlign(alignment), "");
}

[[nodiscard]] llvm::Value *_translate_accel_trace(
Expand All @@ -1707,7 +1710,7 @@ class FallbackCodegen {
auto hit_type = _translate_type(Type::of<luisa::compute::SurfaceHit>(), false);

auto hit_alloca = b.CreateAlloca(hit_type, nullptr, "");
hit_alloca->setAlignment(llvm::Align(8u));
hit_alloca->setAlignment(llvm::Align(Type::of<luisa::compute::SurfaceHit>()->alignment()));

// Extract ray components
auto compressed_origin = b.CreateExtractValue(llvm_ray, 0, "");
Expand Down

0 comments on commit b683555

Please sign in to comment.