Bad legalization?

I am getting an assert on a bad legalization.

Assertion failed: Result.getValueType() == Op.getValueType() && "Bad
legalization!", file ..\..\lib\CodeGen\SelectionDAG\LegalizeDAG.cpp,
line 3976

Can someone explain to me what this means in term of backend code
generation, how it might be occurring, and possible ways to fix this? I
don't see how the value type of an operation and the result being the
same can cause an issue.

The IR code in question is as follows:

define void @ test_unary_func_absolute_value(i32 %x, i32 addrspace(11)*
%result) {


        %call = tail call i32 (...)* @abs( i32 %x ) ; <i32>

        store i32 %call, i32 addrspace(11)* %result

        ret void


declare i32 @abs(...)

Micah Villmow

Systems Engineer

Advanced Technology & Performance

Advanced Micro Devices Inc.

4555 Great America Pkwy,

Santa Clara, CA. 95054

P: 408-572-6219

F: 408-572-6596

This roughly means that the type of the result of running
SelectionDAGLegalize::LegalizeOp is not the same as the type of the
argument to LegalizeOp. Most likely, your custom legalization messing
up, although it's possible there's a bug in


When you run into issues like this, it helps if you provide a bit more information. Please dump out Result, Op, DAG, and / or the DAG before legalization starts.

Quite the opposite. It’s asserting because the value types of op (before legalization) and Result (after) are different.


It is conceivable that it’s sensitive to the name “abs”, try changing it.