[Reassociate] add test for shl+or; NFC
authorSanjay Patel <spatel@rotateright.com>
Fri, 5 Feb 2021 18:42:03 +0000 (13:42 -0500)
committerSanjay Patel <spatel@rotateright.com>
Fri, 5 Feb 2021 19:25:19 +0000 (14:25 -0500)
llvm/test/Transforms/Reassociate/add-like-or.ll

index dec1b3f..757a10c 100644 (file)
@@ -1,6 +1,21 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -reassociate -S | FileCheck %s
 
+define i32 @shl_add(i8 %x) {
+; CHECK-LABEL: @shl_add(
+; CHECK-NEXT:    [[CONV:%.*]] = zext i8 [[X:%.*]] to i32
+; CHECK-NEXT:    [[SHL:%.*]] = shl nuw nsw i32 [[CONV]], 8
+; CHECK-NEXT:    [[SHL2:%.*]] = shl nuw nsw i32 [[CONV]], 16
+; CHECK-NEXT:    [[ADD:%.*]] = or i32 [[SHL]], [[SHL2]]
+; CHECK-NEXT:    ret i32 [[ADD]]
+;
+  %conv = zext i8 %x to i32
+  %shl = shl nuw nsw i32 %conv, 8
+  %shl2 = shl nuw nsw i32 %conv, 16
+  %add = or i32 %shl, %shl2
+  ret i32 %add
+}
+
 ; If we don't know that operands have no common bits set,
 ; we can't convert the `or` into an `add`.
 define i32 @test1(i32 %a, i32 %b) {