@@ -181,18 +181,22 @@ function emit_intrinsic!(ctx::CGCtx, ::typeof(Intrinsics.constant), args)
181181 tile_shape = collect (Int, shape)
182182 validate_tile_shape (tile_shape, " full" )
183183
184- # Extract value
185- value = @something get_constant (ctx, args[2 ]) throw (IRError (" full() value must be a compile-time constant" ))
186-
187184 # Extract dtype from Type{T} argument
188185 elem_type = @something get_constant (ctx, args[3 ]) throw (IRError (" constant() requires a compile-time element type" ))
189186
190187 dtype = julia_to_tile_dtype! (tt, elem_type)
191188 tile_type = tile_type! (tt, dtype, tile_shape)
192189
193- # Create constant directly at target shape
194- value_bytes = constant_to_bytes (value, elem_type)
195- result = encode_ConstantOp! (cb, tile_type, value_bytes)
190+ tv = emit_value! (ctx, args[2 ])
191+ tv === nothing && throw (IRError (" full() value must be a constant or a runtime scalar" ))
192+ if tv. constant != = nothing
193+ # Compile-time constant: use ConstantOp directly
194+ value_bytes = constant_to_bytes (something (tv. constant), elem_type)
195+ result = encode_ConstantOp! (cb, tile_type, value_bytes)
196+ else
197+ # Runtime value: broadcast 0D tile to the target shape
198+ result = broadcast_tile_to_shape! (cb, tt, tv, tile_shape, dtype)
199+ end
196200
197201 CGVal (result, tile_type, Tile{elem_type, Tuple{tile_shape... }}, tile_shape)
198202end
0 commit comments