-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CGP] Fix missing sign extension for base offset in optimizeMemoryInst #161377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nikic
merged 5 commits into
llvm:main
from
vladimirradosavljevic:fix_signextension_in_cgp
Oct 10, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
926ce13
[CGP] NFC: Add pre-commit test
vladimirradosavljevic a0ca124
[CGP] Fix missing sign extension for base offset in optimizeMemoryInst
vladimirradosavljevic 57216c7
[CGP] Address comments
vladimirradosavljevic 68cdb30
[CGP] NFC: Add test that exposes another issue
vladimirradosavljevic 9691142
[CGP] Fix issue in one more place
vladimirradosavljevic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
52 changes: 52 additions & 0 deletions
52
llvm/test/Transforms/CodeGenPrepare/X86/baseoffs-sext-bug.ll
This file contains hidden or 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,52 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' < %s | FileCheck --check-prefix=GEP %s | ||
; RUN: opt -S -passes='require<profile-summary>,function(codegenprepare)' -addr-sink-using-gep=false < %s | FileCheck --check-prefix=NO-GEP %s | ||
|
||
target triple = "x86_64--linux-gnu" | ||
target datalayout = "e-m:e-p0:128:128-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | ||
; -p0:128:128 is added to ensure that transformation will be triggered. | ||
|
||
define i128 @test(i128 %arg) { | ||
; GEP-LABEL: define i128 @test( | ||
; GEP-SAME: i128 [[ARG:%.*]]) { | ||
; GEP-NEXT: [[ENTRY:.*]]: | ||
; GEP-NEXT: [[CMP:%.*]] = icmp ugt i128 [[ARG]], 10 | ||
; GEP-NEXT: br i1 [[CMP]], label %[[THEN:.*]], label %[[EXIT:.*]] | ||
; GEP: [[THEN]]: | ||
; GEP-NEXT: [[SUNKADDR:%.*]] = inttoptr i128 [[ARG]] to ptr | ||
; GEP-NEXT: [[SUNKADDR1:%.*]] = getelementptr i8, ptr [[SUNKADDR]], i128 -32 | ||
; GEP-NEXT: [[LOAD:%.*]] = load i128, ptr [[SUNKADDR1]], align 16 | ||
; GEP-NEXT: br label %[[EXIT]] | ||
; GEP: [[EXIT]]: | ||
; GEP-NEXT: [[PHI:%.*]] = phi i128 [ [[LOAD]], %[[THEN]] ], [ 0, %[[ENTRY]] ] | ||
; GEP-NEXT: ret i128 [[PHI]] | ||
; | ||
; NO-GEP-LABEL: define i128 @test( | ||
; NO-GEP-SAME: i128 [[ARG:%.*]]) { | ||
; NO-GEP-NEXT: [[ENTRY:.*]]: | ||
; NO-GEP-NEXT: [[CMP:%.*]] = icmp ugt i128 [[ARG]], 10 | ||
; NO-GEP-NEXT: br i1 [[CMP]], label %[[THEN:.*]], label %[[EXIT:.*]] | ||
; NO-GEP: [[THEN]]: | ||
; NO-GEP-NEXT: [[SUNKADDR:%.*]] = add i128 [[ARG]], -32 | ||
; NO-GEP-NEXT: [[SUNKADDR1:%.*]] = inttoptr i128 [[SUNKADDR]] to ptr | ||
; NO-GEP-NEXT: [[LOAD:%.*]] = load i128, ptr [[SUNKADDR1]], align 16 | ||
; NO-GEP-NEXT: br label %[[EXIT]] | ||
; NO-GEP: [[EXIT]]: | ||
; NO-GEP-NEXT: [[PHI:%.*]] = phi i128 [ [[LOAD]], %[[THEN]] ], [ 0, %[[ENTRY]] ] | ||
; NO-GEP-NEXT: ret i128 [[PHI]] | ||
; | ||
entry: | ||
%add = add i128 %arg, -32 | ||
%cmp = icmp ugt i128 %arg, 10 | ||
br i1 %cmp, label %then, label %exit | ||
|
||
then: | ||
%inttoptr = inttoptr i128 %add to ptr | ||
%load = load i128, ptr %inttoptr, align 16 | ||
br label %exit | ||
|
||
exit: | ||
%phi = phi i128 [ %load, %then ], [ 0, %entry ] | ||
ret i128 %phi | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.