Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) {
if (Instruction *R = FoldOpIntoSelect(I, SI))
return R;

if (Constant *CUI = dyn_cast<Constant>(Op1))
Constant *CUI;
if (match(Op1, m_ImmConstant(CUI)))
if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I))
return Res;

Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Transforms/InstCombine/shl-twice-constant.ll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two instructions in this test shouldn't be needed, it can be reduced to:

@c = external constant i8
@c2 = external constant i8

define i64 @testfunc() {
  %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)
  %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)
  ret i64 %shl2
}
```.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test adjusted. thank you for the review :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s

@c = external constant i8
@c2 = external constant i8

define i64 @testfunc() {
; CHECK-LABEL: @testfunc(
; CHECK-NEXT: [[SHL1:%.*]] = shl nuw i64 1, ptrtoint (ptr @c2 to i64)
; CHECK-NEXT: [[SHL2:%.*]] = shl i64 [[SHL1]], ptrtoint (ptr @c to i64)
; CHECK-NEXT: ret i64 [[SHL2]]
;
%shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)
%shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)
ret i64 %shl2
}
Loading