[PATCH] D72048: [InstCombine] Preserve nuw on sub of geps (PR44419)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 02:41:13 PST 2020


lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Thank you for looking into this.



================
Comment at: llvm/test/Transforms/InstCombine/sub-gep.ll:30-41
 define i64 @test_nuw([0 x i32]* %base, i64 %idx) {
 ; CHECK-LABEL: @test_nuw(
-; CHECK-NEXT:    [[P2_IDX:%.*]] = shl i64 [[IDX:%.*]], 2
+; CHECK-NEXT:    [[P2_IDX:%.*]] = shl nuw i64 [[IDX:%.*]], 2
 ; CHECK-NEXT:    ret i64 [[P2_IDX]]
 ;
   %p1 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 0
   %p2 = getelementptr [0 x i32], [0 x i32]* %base, i64 0, i64 %idx
----------------
```
----------------------------------------
define i64 @test_nuw(* %base, i64 %idx) {
%0:
  %p1 = gep * %base, 0 x i64 0, 4 x i64 0
  %p2 = gep * %base, 0 x i64 0, 4 x i64 %idx
  %i1 = ptrtoint * %p1 to i64
  %i2 = ptrtoint * %p2 to i64
  %d = sub nuw i64 %i2, %i1
  ret i64 %d
}
=>
define i64 @test_nuw(* %base, i64 %idx) {
%0:
  %P2_IDX = shl nuw i64 %idx, 2
  ret i64 %P2_IDX
}
Transformation doesn't verify!
ERROR: Target is more poisonous than source

Example:
* %base = null
i64 %idx = undef

Source:
* %p1 = null
* %p2 = null    [based on undef value]
i64 %i1 = #x0000000000000000 (0)
i64 %i2 = #x0000000000000000 (0)
i64 %d = #x0000000000000000 (0)

Target:
i64 %P2_IDX = poison
Source value: #x0000000000000000 (0)
Target value: poison

Summary:
  0 correct transformations
  1 incorrect transformations
  0 errors

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72048





More information about the llvm-commits mailing list