forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jacob Knowlton - Assignment 2 Optimization (llvm#58)
* Added working optimization * Finished tests * Added back whitespace before return * Wrapped optimization in scope block --------- Co-authored-by: Jacob Knowlton <u1117344@utah.edu>
- Loading branch information
1 parent
2817101
commit be4d746
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
; Test 1: Simple Case (Optimization Applied) | ||
define i1 @test1(i16 %x) { | ||
%mul1 = mul nsw i16 %x, 3 ; Positive constant | ||
%mul2 = mul nsw i16 %mul1, %x | ||
%cmp = icmp sge i16 %mul2, 0 | ||
ret i1 %cmp | ||
} | ||
|
||
; CHECK-LABEL: @test1( | ||
; CHECK-NEXT: ret i1 true | ||
|
||
; Test 2: No `nsw` Flag (Optimization Not Applied) | ||
define i1 @test2(i16 %x) { | ||
%mul1 = mul i16 %x, 3 ; No 'nsw' flag | ||
%mul2 = mul i16 %mul1, %x | ||
%cmp = icmp sge i16 %mul2, 0 | ||
ret i1 %cmp | ||
} | ||
|
||
; CHECK-LABEL: @test2( | ||
; CHECK-NOT: ret i1 true | ||
; CHECK: ret i1 %cmp | ||
|
||
; Test 3: Non-Positive Constant (Optimization Not Applied) | ||
define i1 @test3(i16 %x) { | ||
%mul1 = mul nsw i16 %x, -5 ; Non-positive constant | ||
%mul2 = mul nsw i16 %mul1, %x | ||
%cmp = icmp sge i16 %mul2, 0 | ||
ret i1 %cmp | ||
} | ||
|
||
; CHECK-LABEL: @test3( | ||
; CHECK-NOT: ret i1 true | ||
; CHECK: ret i1 %cmp |