This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner][AMDGPU][X86] Turn cttz/ctlz into cttz_zero_undef/ctlz_zero_undef if we can prove the input is never zero
ClosedPublic

Authored by craig.topper on Feb 6 2018, 2:18 PM.

Details

Summary

X86 currently has a late DAG combine after cttz/ctlz are turned into BSR+BSF+CMOV to detect this and remove the CMOV. But we should be able to do this much earlier and avoid creating the cmov all together.

For the changed AMDGPU test case it appears that previously the i8 cttz was type legalized to i16 which introduced an OR with 256 in order to limit the result to 8 on the widened type. At this point the result is known to never be zero, but nothing checked that. Then operation legalization is told to promote all i16 cttz to i32. This introduces an extend and a truncate and another OR with 65536 to limit the result to 16. With the DAG combiner change we are able to prevent the creation of the second OR since the opcode will have been changed to cttz_zero_undef after the first OR. I the lack of the OR caused the instruction to change to v_ffbl_b32_sdwa

Diff Detail

Event Timeline

craig.topper created this revision.Feb 6 2018, 2:18 PM
arsenm accepted this revision.Feb 6 2018, 2:26 PM

LGTM

This revision is now accepted and ready to land.Feb 6 2018, 2:26 PM
This revision was automatically updated to reflect the committed changes.