[PATCH] D107552: [InstCombine] Combine lshr of add that intends to get the carry as llvm.uadd.with.overflow

Abinav Puthan Purayil via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 9 02:36:02 PDT 2021


abinavpp updated this revision to Diff 365130.
abinavpp added a comment.

Fixed the case in which the add of the uaddo won't dominate the original trunc use. For e.g.:

target datalayout = "n32"

declare void @true()
declare void @false()

define i32 @lshr_32_add_zext_trunc(i32 %a, i32 %b) {

  %zext.a = zext i32 %a to i64
  %zext.b = zext i32 %b to i64
  %add = add i64 %zext.a, %zext.b
  %trunc.add = trunc i64 %add to i32
  %cmp = icmp ult i32 %a, %b
  br i1 %cmp, label %brTrue, label %brFalse

brTrue:

  %shr = lshr i64 %add, 32
  %trunc.shr = trunc i64 %shr to i32
  %retTrue = add i32 %trunc.add, %trunc.shr
  call void @true()
  br label %brMerge

brFalse:

  %retFalse = add i32 %trunc.add, 12
  call void @false()
  br label %brMerge

brMerge:

  %ret = phi i32 [ %retTrue, %brTrue ], [ %retFalse, %brFalse ]
  ret i32 %ret

}


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107552/new/

https://reviews.llvm.org/D107552

Files:
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/test/Transforms/InstCombine/shift-add.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107552.365130.patch
Type: text/x-patch
Size: 6337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210809/4a8c4f1f/attachment.bin>


More information about the llvm-commits mailing list