Skip to content

Commit 5e8a54a

Browse files
committed
drop ub implying attributes
1 parent bc77733 commit 5e8a54a

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

clang/test/Headers/__clang_hip_math.hip

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,7 +4983,7 @@ extern "C" __device__ double test_normcdfinv(double x) {
49834983
// DEFAULT-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
49844984
// DEFAULT-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5NORMFIPKF_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP20:![0-9]+]]
49854985
// DEFAULT: _ZL5normfiPKf.exit.loopexit:
4986-
// DEFAULT-NEXT: [[TMP1:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[ADD_I]])
4986+
// DEFAULT-NEXT: [[TMP1:%.*]] = tail call contract float @llvm.sqrt.f32(float [[ADD_I]])
49874987
// DEFAULT-NEXT: br label [[_ZL5NORMFIPKF_EXIT]]
49884988
// DEFAULT: _ZL5normfiPKf.exit:
49894989
// DEFAULT-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL5NORMFIPKF_EXIT_LOOPEXIT]] ]
@@ -5005,7 +5005,7 @@ extern "C" __device__ double test_normcdfinv(double x) {
50055005
// FINITEONLY-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
50065006
// FINITEONLY-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5NORMFIPKF_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP20:![0-9]+]]
50075007
// FINITEONLY: _ZL5normfiPKf.exit.loopexit:
5008-
// FINITEONLY-NEXT: [[TMP1:%.*]] = tail call nnan ninf contract noundef float @llvm.sqrt.f32(float [[ADD_I]])
5008+
// FINITEONLY-NEXT: [[TMP1:%.*]] = tail call nnan ninf contract float @llvm.sqrt.f32(float [[ADD_I]])
50095009
// FINITEONLY-NEXT: br label [[_ZL5NORMFIPKF_EXIT]]
50105010
// FINITEONLY: _ZL5normfiPKf.exit:
50115011
// FINITEONLY-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL5NORMFIPKF_EXIT_LOOPEXIT]] ]
@@ -5027,7 +5027,7 @@ extern "C" __device__ double test_normcdfinv(double x) {
50275027
// APPROX-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
50285028
// APPROX-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5NORMFIPKF_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP20:![0-9]+]]
50295029
// APPROX: _ZL5normfiPKf.exit.loopexit:
5030-
// APPROX-NEXT: [[TMP1:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[ADD_I]])
5030+
// APPROX-NEXT: [[TMP1:%.*]] = tail call contract float @llvm.sqrt.f32(float [[ADD_I]])
50315031
// APPROX-NEXT: br label [[_ZL5NORMFIPKF_EXIT]]
50325032
// APPROX: _ZL5normfiPKf.exit:
50335033
// APPROX-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL5NORMFIPKF_EXIT_LOOPEXIT]] ]
@@ -5049,7 +5049,7 @@ extern "C" __device__ double test_normcdfinv(double x) {
50495049
// NCRDIV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
50505050
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5NORMFIPKF_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP21:![0-9]+]]
50515051
// NCRDIV: _ZL5normfiPKf.exit.loopexit:
5052-
// NCRDIV-NEXT: [[TMP1:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[ADD_I]]), !fpmath [[META22:![0-9]+]]
5052+
// NCRDIV-NEXT: [[TMP1:%.*]] = tail call contract float @llvm.sqrt.f32(float [[ADD_I]])
50535053
// NCRDIV-NEXT: br label [[_ZL5NORMFIPKF_EXIT]]
50545054
// NCRDIV: _ZL5normfiPKf.exit:
50555055
// NCRDIV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL5NORMFIPKF_EXIT_LOOPEXIT]] ]
@@ -5071,7 +5071,7 @@ extern "C" __device__ double test_normcdfinv(double x) {
50715071
// AMDGCNSPIRV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
50725072
// AMDGCNSPIRV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5NORMFIPKF_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP21:![0-9]+]]
50735073
// AMDGCNSPIRV: _ZL5normfiPKf.exit.loopexit:
5074-
// AMDGCNSPIRV-NEXT: [[TMP1:%.*]] = tail call contract noundef addrspace(4) float @llvm.sqrt.f32(float [[ADD_I]])
5074+
// AMDGCNSPIRV-NEXT: [[TMP1:%.*]] = tail call contract addrspace(4) float @llvm.sqrt.f32(float [[ADD_I]])
50755075
// AMDGCNSPIRV-NEXT: br label [[_ZL5NORMFIPKF_EXIT]]
50765076
// AMDGCNSPIRV: _ZL5normfiPKf.exit:
50775077
// AMDGCNSPIRV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL5NORMFIPKF_EXIT_LOOPEXIT]] ]
@@ -5097,7 +5097,7 @@ extern "C" __device__ float test_normf(int x, const float *y) {
50975097
// DEFAULT-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
50985098
// DEFAULT-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP21:![0-9]+]]
50995099
// DEFAULT: _ZL4normiPKd.exit.loopexit:
5100-
// DEFAULT-NEXT: [[TMP1:%.*]] = tail call contract noundef double @llvm.sqrt.f64(double [[ADD_I]])
5100+
// DEFAULT-NEXT: [[TMP1:%.*]] = tail call contract double @llvm.sqrt.f64(double [[ADD_I]])
51015101
// DEFAULT-NEXT: br label [[_ZL4NORMIPKD_EXIT]]
51025102
// DEFAULT: _ZL4normiPKd.exit:
51035103
// DEFAULT-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL4NORMIPKD_EXIT_LOOPEXIT]] ]
@@ -5119,7 +5119,7 @@ extern "C" __device__ float test_normf(int x, const float *y) {
51195119
// FINITEONLY-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
51205120
// FINITEONLY-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP21:![0-9]+]]
51215121
// FINITEONLY: _ZL4normiPKd.exit.loopexit:
5122-
// FINITEONLY-NEXT: [[TMP1:%.*]] = tail call nnan ninf contract noundef double @llvm.sqrt.f64(double [[ADD_I]])
5122+
// FINITEONLY-NEXT: [[TMP1:%.*]] = tail call nnan ninf contract double @llvm.sqrt.f64(double [[ADD_I]])
51235123
// FINITEONLY-NEXT: br label [[_ZL4NORMIPKD_EXIT]]
51245124
// FINITEONLY: _ZL4normiPKd.exit:
51255125
// FINITEONLY-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL4NORMIPKD_EXIT_LOOPEXIT]] ]
@@ -5141,7 +5141,7 @@ extern "C" __device__ float test_normf(int x, const float *y) {
51415141
// APPROX-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
51425142
// APPROX-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP21:![0-9]+]]
51435143
// APPROX: _ZL4normiPKd.exit.loopexit:
5144-
// APPROX-NEXT: [[TMP1:%.*]] = tail call contract noundef double @llvm.sqrt.f64(double [[ADD_I]])
5144+
// APPROX-NEXT: [[TMP1:%.*]] = tail call contract double @llvm.sqrt.f64(double [[ADD_I]])
51455145
// APPROX-NEXT: br label [[_ZL4NORMIPKD_EXIT]]
51465146
// APPROX: _ZL4normiPKd.exit:
51475147
// APPROX-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL4NORMIPKD_EXIT_LOOPEXIT]] ]
@@ -5161,9 +5161,9 @@ extern "C" __device__ float test_normf(int x, const float *y) {
51615161
// NCRDIV-NEXT: [[ADD_I]] = fadd contract double [[__R_0_I4]], [[MUL_I]]
51625162
// NCRDIV-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds nuw i8, ptr [[__A_ADDR_0_I3]], i64 8
51635163
// NCRDIV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
5164-
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP23:![0-9]+]]
5164+
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP22:![0-9]+]]
51655165
// NCRDIV: _ZL4normiPKd.exit.loopexit:
5166-
// NCRDIV-NEXT: [[TMP1:%.*]] = tail call contract noundef double @llvm.sqrt.f64(double [[ADD_I]])
5166+
// NCRDIV-NEXT: [[TMP1:%.*]] = tail call contract double @llvm.sqrt.f64(double [[ADD_I]])
51675167
// NCRDIV-NEXT: br label [[_ZL4NORMIPKD_EXIT]]
51685168
// NCRDIV: _ZL4normiPKd.exit:
51695169
// NCRDIV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL4NORMIPKD_EXIT_LOOPEXIT]] ]
@@ -5185,7 +5185,7 @@ extern "C" __device__ float test_normf(int x, const float *y) {
51855185
// AMDGCNSPIRV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
51865186
// AMDGCNSPIRV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL4NORMIPKD_EXIT_LOOPEXIT:%.*]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP22:![0-9]+]]
51875187
// AMDGCNSPIRV: _ZL4normiPKd.exit.loopexit:
5188-
// AMDGCNSPIRV-NEXT: [[TMP1:%.*]] = tail call contract noundef addrspace(4) double @llvm.sqrt.f64(double [[ADD_I]])
5188+
// AMDGCNSPIRV-NEXT: [[TMP1:%.*]] = tail call contract addrspace(4) double @llvm.sqrt.f64(double [[ADD_I]])
51895189
// AMDGCNSPIRV-NEXT: br label [[_ZL4NORMIPKD_EXIT]]
51905190
// AMDGCNSPIRV: _ZL4normiPKd.exit:
51915191
// AMDGCNSPIRV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP1]], [[_ZL4NORMIPKD_EXIT_LOOPEXIT]] ]
@@ -5727,7 +5727,7 @@ extern "C" __device__ double test_rint(double x) {
57275727
// NCRDIV-NEXT: [[ADD_I]] = fadd contract float [[__R_0_I4]], [[MUL_I]]
57285728
// NCRDIV-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds nuw i8, ptr [[__A_ADDR_0_I3]], i64 4
57295729
// NCRDIV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
5730-
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL6RNORMFIPKF_EXIT]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP24:![0-9]+]]
5730+
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL6RNORMFIPKF_EXIT]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP23:![0-9]+]]
57315731
// NCRDIV: _ZL6rnormfiPKf.exit:
57325732
// NCRDIV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY]] ], [ [[ADD_I]], [[WHILE_BODY_I]] ]
57335733
// NCRDIV-NEXT: [[CALL_I:%.*]] = tail call contract noundef float @__ocml_rsqrt_f32(float noundef [[__R_0_I_LCSSA]]) #[[ATTR15]]
@@ -5831,7 +5831,7 @@ extern "C" __device__ float test_rnormf(int x, const float* y) {
58315831
// NCRDIV-NEXT: [[ADD_I]] = fadd contract double [[__R_0_I4]], [[MUL_I]]
58325832
// NCRDIV-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds nuw i8, ptr [[__A_ADDR_0_I3]], i64 8
58335833
// NCRDIV-NEXT: [[TOBOOL_NOT_I:%.*]] = icmp eq i32 [[DEC_I]], 0
5834-
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5RNORMIPKD_EXIT]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP25:![0-9]+]]
5834+
// NCRDIV-NEXT: br i1 [[TOBOOL_NOT_I]], label [[_ZL5RNORMIPKD_EXIT]], label [[WHILE_BODY_I]], !llvm.loop [[LOOP24:![0-9]+]]
58355835
// NCRDIV: _ZL5rnormiPKd.exit:
58365836
// NCRDIV-NEXT: [[__R_0_I_LCSSA:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[ADD_I]], [[WHILE_BODY_I]] ]
58375837
// NCRDIV-NEXT: [[CALL_I:%.*]] = tail call contract noundef double @__ocml_rsqrt_f64(double noundef [[__R_0_I_LCSSA]]) #[[ATTR15]]
@@ -6636,7 +6636,7 @@ extern "C" __device__ double test_sinpi(double x) {
66366636
//
66376637
// NCRDIV-LABEL: @test_sqrtf(
66386638
// NCRDIV-NEXT: entry:
6639-
// NCRDIV-NEXT: [[TMP0:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[X:%.*]]), !fpmath [[META22]]
6639+
// NCRDIV-NEXT: [[TMP0:%.*]] = tail call contract noundef float @llvm.sqrt.f32(float [[X:%.*]]), !fpmath [[META25:![0-9]+]]
66406640
// NCRDIV-NEXT: ret float [[TMP0]]
66416641
//
66426642
// AMDGCNSPIRV-LABEL: @test_sqrtf(

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,8 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN,
19941994
}
19951995
Clone = InsertNewInstBefore(Clone, OpBB->getTerminator()->getIterator());
19961996
Clones.insert({OpBB, Clone});
1997+
// We may have speculated the instruction.
1998+
Clone->dropUBImplyingAttrsAndMetadata();
19971999
}
19982000

19992001
NewPhiValues[OpIndex] = Clone;

llvm/test/Transforms/InstCombine/phi.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,3 +2998,30 @@ join:
29982998
%cmp = icmp eq i32 %phi, 0
29992999
ret i1 %cmp
30003000
}
3001+
3002+
declare void @may_exit()
3003+
3004+
define i32 @intrinsic_over_phi_noundef(i1 %c, i1 %c2, i32 %a) {
3005+
; CHECK-LABEL: @intrinsic_over_phi_noundef(
3006+
; CHECK-NEXT: entry:
3007+
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
3008+
; CHECK: if:
3009+
; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.umax.i32(i32 [[A:%.*]], i32 1)
3010+
; CHECK-NEXT: br label [[JOIN]]
3011+
; CHECK: join:
3012+
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[TMP0]], [[IF]] ], [ 1, [[ENTRY:%.*]] ]
3013+
; CHECK-NEXT: call void @may_exit()
3014+
; CHECK-NEXT: ret i32 [[PHI]]
3015+
;
3016+
entry:
3017+
br i1 %c, label %if, label %join
3018+
3019+
if:
3020+
br label %join
3021+
3022+
join:
3023+
%phi = phi i32 [ %a, %if ], [ 0, %entry ]
3024+
call void @may_exit()
3025+
%umax = call noundef i32 @llvm.umax(i32 noundef %phi, i32 1)
3026+
ret i32 %umax
3027+
}

0 commit comments

Comments
 (0)