[GlobalIsel] Use aext in ctlz_zero_undef widenScalar expansion#181506
[GlobalIsel] Use aext in ctlz_zero_undef widenScalar expansion#181506AlexMaclean merged 2 commits intollvm:mainfrom
Conversation
|
@llvm/pr-subscribers-backend-arm @llvm/pr-subscribers-llvm-globalisel Author: Alex MacLean (AlexMaclean) ChangesFull diff: https://github.com/llvm/llvm-project/pull/181506.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 41b79ccb4e4d1..ffd0814f86010 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -2816,6 +2816,7 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
switch (Opcode) {
case TargetOpcode::G_CTTZ:
case TargetOpcode::G_CTTZ_ZERO_UNDEF:
+ case TargetOpcode::G_CTLZ_ZERO_UNDEF: // undef bits shifted out below
ExtOpc = TargetOpcode::G_ANYEXT;
break;
case TargetOpcode::G_CTLS:
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
arsenm
left a comment
There was a problem hiding this comment.
I'd expect this to be caught by other optimizations, but I think GlobalISel is still missing SimplifyDemandedBits
Yea, I think this is missing. Even if it were supported, since the GIsel combiner is more opt-in I think it can't hurt to generate the best sequence of instructions for this lowering directly, instead of relying on optimization. Any concerns with this change as is? |
Use
G_ANYEXTinstead ofG_ZEXTwhen widening the source ofG_CTLZ_ZERO_UNDEF. The extended upper bits are immediately shifted out by the subsequent left-shift, so zero-extending is unnecessarily constraining.Before:
After: