Skip to content

InstCombine unsafely drops zero extensions of shift amounts when combining shifts - miscompile #44147

@llvmbot

Description

@llvmbot
Bugzilla Link 44802
Resolution FIXED
Resolved on Apr 02, 2021 11:24
Version trunk
OS Linux
Blocks #43900
Reporter LLVM Bugzilla Contributor
CC @zmodem,@LebedevRI,@RKSimon,@meheff,@nikic,@regehr,@rotateright
Fixed by commit(s) 425ef99 781d077 6f807ca 2855c8f

Extended Description

Reproducer: https://rise4fun.com/Alive/ne8y

In InstCombiner::reassociateShiftAmtsOfTwoSameDirectionShifts(), when identifying two shifts to combine, it does so while ignoring any zero-extensions of those values. In the problematic case above, the values were both i1s zero-extended to i3s.

When their zero-extensions are dropped (taking them back to i1s) their sum becomes an xor in SimplifyAddInst(), which causes the shift to basically disappear (and to be dropped in a later pass).

I'm not familiar with the history of this code, particularly why the zero extensions are ignored, but changing the code to leave them in place does fix the issue.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzilla

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions