This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] fold (sext (sext_inreg x)) -> (sext (trunc x))
ClosedPublic

Authored by deadalnix on Jan 4 2023, 7:32 AM.

Details

Summary

This fixes a regression introduced by D127115 in test/CodeGen/PowerPC/store-forward-be64.ll

Diff Detail

Event Timeline

deadalnix created this revision.Jan 4 2023, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2023, 7:32 AM
deadalnix requested review of this revision.Jan 4 2023, 7:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2023, 7:32 AM
deadalnix retitled this revision from [DAGCOmbine] fold (sext (sext_inreg x)) -> (sext (trunc x)) to [DAGCombine] fold (sext (sext_inreg x)) -> (sext (trunc x)).Jan 4 2023, 9:07 AM

I'm a bit worried this will end up fighting the existing "(sext (truncate x)) -> (sextinreg x)" fold

Yes, it shouldn't in itself, but throw another transform in the loop, and it may well be.

Is there another approach you are thinking of? I thought about doing just (sext (sext_inreg (trunc x))) -> (sext (trunc x)) but that seemed too topical.

If you're after test cases: https://gcc.godbolt.org/z/dPzYvz6dW - you might want to look to see why this isn't helping

This is from x86/sdiv_fix.ll which is currently repeating sign extensions: https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/X86/sdiv_fix.ll#L68:L71

      t2: i32,ch = CopyFromReg t0, Register:i32 %0
    t21: i16 = truncate t2
  t22: i16 = sign_extend_inreg t21, ValueType:ch:i8
t53: i32 = sign_extend t22
; X64-NEXT:    movsbl %dil, %eax
; X64-NEXT:    movsbl %sil, %ecx
; X64-NEXT:    movswl %cx, %esi  ; <-- ECX IS ALREADY SIGN-EXTENDED FROM i8
; X64-NEXT:    movswl %ax, %ecx  ; <-- EAX IS ALREADY SIGN-EXTENDED FROM i8
deadalnix updated this revision to Diff 487567.Jan 9 2023, 3:01 PM

Specialize the transform, which avoids problems with the transform creating an infinite loop.

Make sure we materialize improvements in sdiv_fix.

RKSimon accepted this revision.Jan 10 2023, 8:38 AM

LGTM - cheers

This revision is now accepted and ready to land.Jan 10 2023, 8:38 AM
This revision was landed with ongoing or failed builds.Jan 10 2023, 12:33 PM
This revision was automatically updated to reflect the committed changes.